i'm "attempting" to add a stroke to a rect, and i realized that
NSBezierPath is not available on iPhone SDK, so i'm forced to subclass
the rect...

my StrokeView:UIView class.m is this:

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

- (void)drawRect:(CGRect)rect
        {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 2.0);
        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
        CGContextStrokePath(context);
        }

now in my may app controller.h i have the following:

@class StrokeView;
@interface AppController : UIViewController
        {
        StrokeView *strokeViewClass;
        }

@property (nonatomic, retain) StrokeView *strokeViewClass;

and in the implementation file, i'm calling for the class to be added
as a subview with this:

#import "StrokeView.h"
[self.view insertSubview:strokeViewClass atIndex:1];

totally doesn't work.

On Fri, Jun 19, 2009 at 12:56 PM, David Duncan<david.dun...@apple.com> wrote:
> On Jun 19, 2009, at 9:26 AM, Chunk 1978 wrote:
>
> i don't understand the difference between the 2.  i think i'm suppose
> to simply set the frame size in initWithFrame method, and set
> attributes (like background color, and clipping masks, etc.) in the
> drawRect method.
>
> -initWithFrame: is
> one of the designated initailizers for a UIView (the other is -initWithCoder: for loading from a NIB). When -initWithFrame: completes, the view needs to be initialized to the point that it can do something useful.
> -drawRect: is just for drawing. You should be doing as little as possible inside of -drawRect: and it should all be 100% related to drawing the content of your view. You may read from various properties, but you almost never set them.
> --
> David Duncan
> Apple DTS Animation and Printing
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to