• 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: Drawing an image in a CustomView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing an image in a CustomView


  • Subject: Re: Drawing an image in a CustomView
  • From: Scott Anguish <email@hidden>
  • Date: Tue, 15 Jan 2002 02:07:03 -0500

On Monday, January 14, 2002, at 11:01 PM, Enigmarelle Development wrote:

(code snipped)
- (void)drawRect:(NSRect)rect {
// Drawing code here.
image = [[NSImage alloc] initWithContentsOfFile:@"macosxlogo.gif"];
[simpleImageView setImage:image];
}

Replace 'simpleImageView' with 'self' above & all looks like it should work. (haven't tried it though.) If all you want to do is display an image though, use a borderless NSImageView and set its image in IB. Part of learning Cocoa is learning to be lazy ;)



it'll compile/run ... it won't actually DRAW anything.. and it'll leak BAD.. :-(

move the image line to the initWithFrame, use a different variable to temporarily hold the image than the instance variable (or you can junk the entire accessor approach, but its an excellent habit to get into)
use [self setImage:theImage] in the initWithFrame if you decide to keep it

actually draw the image in drawRect:

[image compositeToPoint:[self bounds].origin operation:NSCompositeSourceOver];


References: 
 >Re: Drawing an image in a CustomView (From: Enigmarelle Development <email@hidden>)

  • Prev by Date: Re: Sorting an NSDictionary?
  • Next by Date: Re: Drawing an image in a CustomView
  • Previous by thread: Re: Drawing an image in a CustomView
  • Next by thread: Re: Drawing an image in a CustomView
  • Index(es):
    • Date
    • Thread