Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 10, 2007, 09:57 AM   #1
vnraju
macrumors newbie
 
Join Date: Jun 2007
changing the background color of a Window in an application

hi all,
is it possible to change the background color of a window?
if it is possible how it is?
any suggestion is appreciated..
vnraju is offline   0 Reply With Quote
Old Aug 10, 2007, 11:12 AM   #2
pianoman
macrumors 68000
 
pianoman's Avatar
 
Join Date: May 2006
EDIT: since it's his own code, this post was irrelevant.

Last edited by pianoman; Aug 11, 2007 at 09:32 AM.
pianoman is offline   0 Reply With Quote
Old Aug 10, 2007, 12:19 PM   #3
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
You can change the background of a view by making a custom subclass of NSView and implementing this method:

Code:
- (void)drawRect:(NSRect)rect {
    // Drawing code here.
	NSColor *white=[NSColor whiteColor];
	[white set];
	NSRectFill([self bounds]);
}
This code just makes the view white, but another colour is easy to achieve by changing "whiteColor" to the color of your choosing.
Eraserhead is offline   0 Reply With Quote
Old Aug 10, 2007, 06:04 PM   #4
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
You never said whether you meant your OWN application, or ANY application. And if it's your own, what are you using to code it?
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Aug 11, 2007, 12:57 AM   #5
vnraju
Thread Starter
macrumors newbie
 
Join Date: Jun 2007
yaaa its my own app...
im trying to change using the code
[myWindow setbackgroungColor:[NSColor blackColor]];
but it....doesn't work....[/COLOR]
vnraju is offline   0 Reply With Quote
Old Aug 11, 2007, 03:26 AM   #6
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
1. Do you get an error, or just nothing happens?

2. Can you post the actual code you're using to do it? In the example you give, the call is misspelled (but probably just a typo here?)

3. Are you sure that myWindow is a valid, initialized window? For example, is it connected to a window in IB? Are you trying to call setBackgroundColor: in a method that gets called before awakeFromNib:? If you are, the window might be invalid or not receive messages yet.
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Aug 11, 2007, 04:14 AM   #7
vnraju
Thread Starter
macrumors newbie
 
Join Date: Jun 2007
Quote:
Originally Posted by HiRez View Post
1. Do you get an error, or just nothing happens?

2. Can you post the actual code you're using to do it? In the example you give, the call is misspelled (but probably just a typo here?)

3. Are you sure that myWindow is a valid, initialized window? For example, is it connected to a window in IB? Are you trying to call setBackgroundColor: in a method that gets called before awakeFromNib:? If you are, the window might be invalid or not receive messages yet.
no it doesn't raise any error..
i made a mistake in posting...to this forum...

and that method will be called after te awakefromnib method.....

Last edited by devilot; Aug 11, 2007 at 11:09 PM. Reason: Merged consecutive posts; please use the "Edit" button
vnraju is offline   0 Reply With Quote
Old Aug 11, 2007, 04:45 AM   #8
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
Quote:
Originally Posted by vnraju View Post
no it doesn't raise any error..
i made a mistake in posting...to this forum...
See my post (#2) for how to do it.
Eraserhead is offline   0 Reply With Quote
Old Aug 11, 2007, 08:44 AM   #9
vnraju
Thread Starter
macrumors newbie
 
Join Date: Jun 2007
Quote:
Originally Posted by Eraserhead View Post
See my post (#2) for how to do it.
i didn;t found............dat......
vnraju is offline   0 Reply With Quote
Old Aug 12, 2007, 01:39 AM   #10
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
It looks like the problem is related to HiRez's #3 item. You could try NSLog-ing your myWindow variable on awakeFromNib, and see if it shows up as a valid object. If not, then there's something wrong with your nib.
kainjow is offline   0 Reply With Quote
Old Aug 12, 2007, 08:32 PM   #11
Fukui
macrumors 68000
 
Fukui's Avatar
 
Join Date: Jul 2002
Quote:
Originally Posted by vnraju View Post
yaaa its my own app...
im trying to change using the code
[myWindow setbackgroungColor:[NSColor blackColor]];
but it....doesn't work....[/COLOR]
Change your window style to textured. Does that work now?
Also, make sure to tell the [window display] after setting the color.
__________________
It's a series of tubes!! - An old man

Last edited by Fukui; Aug 12, 2007 at 08:52 PM.
Fukui is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
UIWebview background color DennisBlah iPhone/iPad Programming 0 May 24, 2014 12:26 PM
Changing Window Background Colour SRF OS X Mavericks (10.9) 7 Mar 5, 2014 03:52 AM
pages background color fleeper Mac Applications and Mac App Store 2 Sep 1, 2013 08:34 PM
UITableView separators don't show after changing table background color straber iPhone/iPad Programming 7 Feb 19, 2013 07:41 PM
Help! Can't change background of a folder window heb11:1 OS X 0 Nov 10, 2012 12:44 AM

Forum Jump

All times are GMT -5. The time now is 05:08 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC