• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Basic, but still confuses me (initWithFrame and drawRect)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic, but still confuses me (initWithFrame and drawRect)


  • Subject: Re: Basic, but still confuses me (initWithFrame and drawRect)
  • From: Chunk 1978 <email@hidden>
  • Date: Fri, 19 Jun 2009 15:20:03 -0400

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<email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Basic, but still confuses me (initWithFrame and drawRect)
      • From: Scott Thompson <email@hidden>
    • Re: Basic, but still confuses me (initWithFrame and drawRect)
      • From: David Duncan <email@hidden>
    • Re: Basic, but still confuses me (initWithFrame and drawRect)
      • From: Shawn Erickson <email@hidden>
References: 
 >Basic, but still confuses me (initWithFrame and drawRect) (From: Chunk 1978 <email@hidden>)
 >Re: Basic, but still confuses me (initWithFrame and drawRect) (From: David Duncan <email@hidden>)

  • Prev by Date: my drawer won't close
  • Next by Date: Re: What is the best way to store some kind of identifying string in an interface builder object?
  • Previous by thread: Re: Basic, but still confuses me (initWithFrame and drawRect)
  • Next by thread: Re: Basic, but still confuses me (initWithFrame and drawRect)
  • Index(es):
    • Date
    • Thread