views:

148

answers:

2

In one of my methods i have this code:

-(void)myMethod {   
   UIBezierPath *circle = [UIBezierPath
                       bezierPathWithOvalInRect:CGRectMake(75, 100, 200, 200)];  
}

How do i get it to show on the view?

I tried addSubview but it gave me an incompatible type error because its expecting a UIView.

I'm sure this must be simple.

Thanks

A: 

You can draw it using either fill or stroke methods for example in custom view's drawInRect: implementation:

- (void)drawRect:(CGRect)rect {
    // Drawing code
    UIBezierPath *circle = [UIBezierPath
                    bezierPathWithOvalInRect:CGRectMake(75, 100, 200, 200)];  
    [circle fill];
}
Vladimir
I tried this, but nothing happens. How do i get the drawing to happen in my custom view?
joec
Create UIView subclass and implement drawRect method there, it works for me at least
Vladimir
+1  A: 

Drawing is the exclusive provision of views. Make a custom view, give it your path, and implement the view's drawRect: method to fill and/or stroke the path.

Peter Hosey
So i made a custom view, then did this in my other view controller `JogShuttle *js = [[JogShuttle alloc] initWithFrame:CGRectMake(...)]; [self.view addSubView:js];` but nothing is drawn on the view?
joec
Could you post some more code? What frame do you set to your js view? Check if your bezier path is inside of view's bounds?
Vladimir
solved it - thanks.
joec
Just interested - what the problem was actually?
Vladimir
I was using stroke, but not setting lineWidth. Doh!
joec
joec: You shouldn't need to. The line width is 1.0 by default (same as in AppKit, Quartz, and PostScript).
Peter Hosey