View Full Version : Setting TextColor/BackColor for NSButton and NSTextField
Apr 13, 2009, 10:29 AM
I have just started working on Mac OS. I have a simple Cocoa Application, using Xcode, with a few controls in it. Now i want to set the front color and back color for these controls.
However, I could not any attributes in the Interface Builder, which could be set to change the default front color and back color of the controls.
Guys, please suggest some ways of doing this!
Apr 13, 2009, 11:15 AM
Font color can be changed by just using the standard color panel for a text field. With your text field selected, go to Tools > Attributes Inspector.
For buttons, look at setAttributedTitle:
For custom background colors on a button you will probably need to subclass NSButton and/or NSButtonCell and draw it yourself. Edit: or provide a custom NSImage.
Apr 13, 2009, 12:04 PM
Cool.... didn't know that it was so easy to set the text color for a TextField :). Thanks a bunch.
However, am not sure how to make use of the setAtrributedTitle field in case of buttons. I have added an Objective C class to my application and also added an object pointing to the Objective C class in the MainMenu.xib file thru Interface Builder. Please suggest what changes I will have to make in the implementation file go get this working for buttons?
Apr 13, 2009, 08:15 PM
Do you have the button connected via an IBOutlet?
Apr 13, 2009, 11:08 PM
I have not yet connected the button via IBOutlet to the Objective C class object. I am not sure how I can add the IBOutlet connection and how I can use it to set the title color.
Any suggestions will be helpful.
Apr 14, 2009, 01:41 AM
Well look at some tutorials or grab a book. This is Cocoa 101, and you should get yourself well familiarized with how this works.