Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Order of controls



Ferhat,


I want to use an image as background of my window. But there is no way to say IB that the image should be draw first so that all controls can be shown.

As an option to Ricky and Sean's suggestions, you could also do something like this:


- (void) awakeFromNib
{
NSImage *backgroundImage = [NSImage imageNamed:@"background"];
NSColor *backgroundColor = [NSColor colorWithPatternImage:backgroundImage];
[_theWindow setBackgroundColor:backgroundColor];
}



This way you don't need to add another view and add all of the window's contents to that view. That can all go on one line, I just broke it up to make it a little easier to read here.


To get the background to update properly, you'll also need to do this in the window's delegate:

- (void)windowDidResize:(NSNotification *)aNotification
{
	[[_theWindow contentView] setNeedsDisplay:YES];	
}


Cocoa is going to tile the image. If you want the image to scale or remain centered in the window, you'll need to update the background color image each time in the -windowDidResize: method.


Since Cocoa draws (and therefore tiles) from the lower-left corner of the window, it probably won't behave the way you'd want it to when resizing the window. I think you can get it to draw from the top-left corner by messing with the window's NSGraphicsContext, but I haven't figured out how to do that yet. Any help here would be appreciated.


-- Dave Batton Mere Mortal Software http://www.Mere-Mortal-Software.com/blog/


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Order of controls (From: Ferhat Ayaz <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.