• 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: How to draw background image in my app window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw background image in my app window


  • Subject: Re: How to draw background image in my app window
  • From: Andy Lee <email@hidden>
  • Date: Sun, 31 May 2009 11:37:29 -0400

On May 31, 2009, at 8:51 AM, Uli Kusterer wrote:
Another approach would be to try changing the class of your content view in Interface builder. Simply click the background of the window, that should show the content view in the inspector. Go to the "Identity" tab and change the class to NSImageView. Then you can probably just do

[(NSImageView*)[myWindow contentView] setImage: [[[NSImage alloc] initWithContentsOfFile: path] autorelease]];

I had the same thought but when I tried it (and added a call to setImageScaling:) the image didn't appear. I wonder what I'm doing wrong:


- (void)awakeFromNib
{
    NSLog(@"-[AppDelegate awakeFromNib]");

NSImage *whiteRoomImage = [NSImage imageNamed:@"WhiteRoom"];
NSImageView *backgroundImageView = (NSImageView *)[_imageWindow contentView];


    NSLog(@"image: %@", whiteRoomImage);
    NSLog(@"contentView: %@", [_imageWindow contentView]);

    [backgroundImageView setImageScaling:NSScaleToFit];
    [backgroundImageView setImage:whiteRoomImage];
}

Yet another approach would be to use IB to add an image view as a subview of the window's content view, and use autoresizing to have it always fill the content view. The benefit of this approach is that you can see the background image in IB, so you can see what it looks like as you lay out its subviews.

--Andy

_______________________________________________

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: 
 >How to draw background image in my app window (From: cocoa learner <email@hidden>)
 >Re: How to draw background image in my app window (From: Nick Zitzmann <email@hidden>)
 >Re: How to draw background image in my app window (From: cocoa learner <email@hidden>)
 >Re: How to draw background image in my app window (From: Michael Vannorsdel <email@hidden>)
 >Re: How to draw background image in my app window (From: cocoa learner <email@hidden>)
 >Re: How to draw background image in my app window (From: Uli Kusterer <email@hidden>)

  • Prev by Date: NSTableView setting row heights
  • Next by Date: Re: [Announce] A Core Data Tutorial Part 2: Polishing the Basics
  • Previous by thread: Re: How to draw background image in my app window
  • Next by thread: [ANN] CocoaHeads Paris #3 - 27th of May (tomorrow)
  • Index(es):
    • Date
    • Thread