Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2010, 09:55 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 6
smt_raven is on a distinguished road
Default displaying custom UIViews

OK, so I have what should be a simple question, so here goes. I've created a class that subclasses UIView, and all it should do is draw a circle on the view I put it in. The class is called Ball and here is the relevant code for it:


- (id)initWithFrameCGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
self.backgroundColor = [self.superview backgroundColor];
return self;
}
else
return nil;

}

- (void)drawRectCGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);

CGContextSetFillColorWithColor(context, currentColor.CGColor);

CGContextAddEllipseInRect(context, self.frame);
CGContextDrawPath(context, kCGPathFillStroke);

}

I created a UIViewController, and tried to add an instance of Ball to it, but where I specified Ball's frame I just get a solid black square. This is the code in the UIViewController where I try to instantiate and display the 'Ball'.

- (void)viewDidLoad {
[super viewDidLoad];

ball = [[Ball alloc] initWithFrame:CGRectMake(100, 100, 40, 40)];

ball.currentColor = [UIColor redColor];

[self.view addSubview:ball];

[self.view setNeedsDisplay];
}

I've set a breakpoint, and I know that the drawRect method of Ball is getting called, but I get a black square instead of a red circle.

Does anyone see where I might have gone wrong here?

Thanks in advance.
smt_raven is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 355
14 members and 341 guests
akacaj, c2matrix, cgokey, esoteric, EXOPTENDAELAX, GHuebner, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Sonuye857, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,652
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Sonuye857
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:21 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0