• 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: David Duncan <email@hidden>
  • Date: Fri, 19 Jun 2009 12:57:25 -0700

On Jun 19, 2009, at 12:20 PM, Chunk 1978 wrote:

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...

I would probably start by looking at the QuartzDemo sample code at <http://developer.apple.com/iPhone/library/samplecode/QuartzDemo/ >


my StrokeView:UIView class.m is this:

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

Changing frame here does nothing. In general you should not change the frame anyway - it is set to what the creator of the view wants it to be.


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

You have not added anything to the current path, so there is nothing to draw. If you want to stroke a rectangle, then you need to add one to the path before you stroke it. See the RectDrawingView demo in the QuartzDemo sample.


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

totally doesn't work.

Where did you create the view? If you didn't create a view (either by alloc/initWithFrame: or by adding it in a NIB and setting up an outlet) then strokeViewClass is likely nil.
--
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


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>)
 >Re: Basic, but still confuses me (initWithFrame and drawRect) (From: Chunk 1978 <email@hidden>)

  • Prev by Date: Re: Basic, but still confuses me (initWithFrame and drawRect)
  • Next by Date: Re: Basic, but still confuses me (initWithFrame and drawRect)
  • 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