• 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
Drawing inside an NSImage?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing inside an NSImage?


  • Subject: Drawing inside an NSImage?
  • From: "Patrick J. Collins" <email@hidden>
  • Date: Sun, 08 Mar 2015 16:12:26 -0700 (PDT)

I have an NSView which has in its "drawRect:" method:

    NSColor *backgroundColor = [NSColor colorWithPatternImage:self.image];
    [backgroundColor setFill];

...

the image method does:

  -(NSImage *)image {
      if (!_image) {
          _image = [[NSImage alloc] initWithSize:self.bounds.size];

          [_image lockFocus];
          [[NSColor blueColor] set];
          NSBezierPath *line = [NSBezierPath bezierPath];

          NSPoint pointA = NSMakePoint(0, 0);
          NSPoint pointB = NSMakePoint(self.bounds.size.width, 0);

          [line moveToPoint:pointA];
          [line lineToPoint:pointB];
          [line stroke];
      }
    return _image;
  }

The resulting line is drawn off center (somewhere around -10px) from the middle
of the NSView...  I would like to have my 0,0 origin be the bottom left corner
of the NSView as I would get if I were to put this line directly in the
drawRect (not using an NSImage): method..

What am I doing wrong here?

Patrick J. Collins
http://collinatorstudios.com

_______________________________________________

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: Drawing inside an NSImage?
      • From: Markus Spoettl <email@hidden>
    • Re: Drawing inside an NSImage?
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Trying to create a 1px width NSBox
  • Next by Date: Re: Trying to create a 1px width NSBox
  • Previous by thread: Re: Trying to create a 1px width NSBox
  • Next by thread: Re: Drawing inside an NSImage?
  • Index(es):
    • Date
    • Thread