Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yygyt

macrumors newbie
Original poster
Feb 4, 2011
7
0
Hello all,

I want to draw several circles of different colors on the screen(Assume that I have a class that draws circle on the screen taking a point and a color as parameters). The problem is that they won't not fit into the screen. I have a question in relation to this problem.

I decided to use uitableview in order to deal with the fitting problem but I don't know how to draw circles on a cell.

It may be straightforward, but I am new to this platform.

Any help will be appreciated.
 
How are you attempting to draw these circles? And what leads you to believe that using a tableview is how to ensure they fit on-screen?
 
How are you attempting to draw these circles? And what leads you to believe that using a tableview is how to ensure they fit on-screen?

I had a class called CircleView that extended UIView and in the drawRect method it calls the following function
Code:
-(void)drawCircleAtPoint:(CGPoint)p withRadius:(CGFloat)rad andPercentage:(int)percent inContext:(CGContextRef)cont{
	UIGraphicsPushContext(cont);
	CGContextBeginPath(cont);
	CGContextAddArc(cont, p.x, p.y, rad, 0, 2*M_PI, NO);
	CGContextSetLineWidth(cont, 1.0);
	[[UIColor colorWithRed:0.19 green:0.31 blue:0.31 alpha:0.65] setFill];
	CGContextFillPath(cont);
	UIGraphicsPopContext();
        ...
}

But using this approach I could draw only one circle on the screen. I want to draw 30 circles. I want to display something like the following pic



For this purpose I thought that I could use a table view. Of course I can accept any other reasonable suggestions.

Sorry for my bad English and I don't know if I am clear enough. If not, please warn me.
 
Last edited:
Any idea that helps me get started is appreciated. Just a general one like "don't use that, use "x", instead" will help me a lot.
 
By changing the point parameter that describes the center of the circle I have multiple circles on the screen.
 
Last edited:
All you gotta do is write your own UIView subclass that draws as many circles as you like wherever. Put one of those views in a scrollview.
 
Which is what you wanted, correct? I'm not sure I understand what your issue is now. Please elaborate.

You are right. That is what I want. The reason I started asking from the beginning is that I wasn't sure if I was going in the right direction.

Thanks for the replies.

Can you tell me how I can add scroll view to the following piece of code.

CircleView.h
Code:
#import <UIKit/UIKit.h>

@class CircleView;
@protocol CircleViewDelegate
-(NSDictionary *)rJInfo:(CircleView *)requestor;
@end

@interface CircleView : UIView {
	id <CircleViewDelegate> delegate;
}
@property (assign) id <CircleViewDelegate> delegate;
@end


CircleView.m
Code:
#import "CircleView.h"
#define START_ARC -0.5*M_PI

@implementation CircleView

@synthesize roomJuzInfoDict;
@synthesize delegate;

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
	if (self) {
    }
    return self;
}

-(void)drawPercentage:(CGPoint)p withRadius:(CGFloat)rad andPercentage:(int)perc inContext:(CGContextRef)cont{
	UIGraphicsPushContext(cont);
	CGContextBeginPath(cont);
	CGContextMoveToPoint(cont, p.x, p.y);
	CGContextAddLineToPoint(cont, p.x, (p.y-rad));
	CGContextAddArc(cont, p.x, p.y, rad, START_ARC, START_ARC+(2*M_PI*perc/100), NO);
	CGContextClosePath(cont);
	[[UIColor colorWithRed:0 green:1 blue:0 alpha:0.4] setFill];
	CGContextFillPath(cont);
	UIGraphicsPopContext();
}

-(void)drawCircleAtPoint:(CGPoint)p withRadius:(CGFloat)rad andPercentage:(int)percent inContext:(CGContextRef)cont{
	UIGraphicsPushContext(cont);
	CGContextBeginPath(cont);
	CGContextAddArc(cont, p.x, p.y, rad, 0, 2*M_PI, NO);
	CGContextSetLineWidth(cont, 1.0);
	[[UIColor colorWithRed:0.19 green:0.31 blue:0.31 alpha:0.65] setFill];
	CGContextFillPath(cont);
	UIGraphicsPopContext();
	[self drawPercentage:p withRadius:rad andPercentage:percent inContext:(UIGraphicsGetCurrentContext())];
}

- (void)drawRect:(CGRect)rect {
	CGPoint midPoint;
	midPoint.x = self.bounds.origin.x + self.bounds.size.width/2;
	midPoint.y = self.bounds.origin.y + self.bounds.size.height/2;
	
	CGFloat size = (self.bounds.size.height<self.bounds.size.width) ? self.bounds.size.height/2 : self.bounds.size.width/2;
	size *= 0.15;
		
	CGContextRef context=UIGraphicsGetCurrentContext();
	int tempPercent=25;
	[self drawCircleAtPoint:midPoint withRadius:size andPercentage:tempPercent inContext:context];
}

- (void)dealloc {
    [super dealloc];
}


@end
 
Can you tell me how I can add scroll view to the following piece of code.

You wouldn't add it to that code. UIScrollView is a container view. You'd need to add the scroll view as a subview to the parent view of your current circle view (seemingly) and then add your circle view as a subview to your scrollview. In other words:
parentView -> scrollView -> circleView
 
You wouldn't add it to that code. UIScrollView is a container view. You'd need to add the scroll view as a subview to the parent view of your current circle view (seemingly) and then add your circle view as a subview to your scrollview. In other words:
parentView -> scrollView -> circleView

Thank you very much. This is what I was searching.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.