08-24-2009, 03:03 PM
#1 (permalink )
iPhone Developer
Join Date: Aug 2009
Posts: 64
Is it possible to programmatically change the font color of UIButton?
hi all again,
im trying to change the font color of a button at runtime (not through the IB). i know that it is possible with labels but i cant get it to work using buttons. can someone give me some more info on this? thanks.
08-24-2009, 03:37 PM
#2 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
setTitleColor:forState:
08-25-2009, 03:47 PM
#3 (permalink )
iPhone Developer
Join Date: Aug 2009
Posts: 64
Quote:
Originally Posted by
BrianSlick
setTitleColor:forState:
thanks but can i use it with rgb colours or do i still have to use one of the default colours?
can i use this?:
Code:
[myButton setTitleColor:[UIColor colorWithRed:100.0 green:100.0 blue:100 alpha:1.0] forState: UIControlStateNormal];
thanks for the help bro.
08-25-2009, 03:51 PM
#4 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Right idea. Check the docs on that method, though. Max is 1.0. Make sure you use floats for each value: 1.0 for blue.
08-25-2009, 03:52 PM
#5 (permalink )
iPhone Developer
Join Date: Aug 2009
Posts: 64
never mind guys, i think i figured it out:
this:
Code:
[myButton setTitleColor:[UIColor colorWithRed:100.0 green:100.0 blue:100 alpha:1.0] forState: UIControlStateNormal];
should be this:
Code:
[myButton setTitleColor:[UIColor colorWithRed:100/255 green:100/255 blue:100/255 alpha:1.0] forState: UIControlStateNormal];
04-23-2010, 10:51 PM
#6 (permalink )
Registered Member
Join Date: Jan 2010
Posts: 11
Quote:
Originally Posted by
losingSkillz
never mind guys, i think i figured it out:
this:
Code:
[myButton setTitleColor:[UIColor colorWithRed:100.0 green:100.0 blue:100 alpha:1.0] forState: UIControlStateNormal];
should be this:
Code:
[myButton setTitleColor:[UIColor colorWithRed:100/255 green:100/255 blue:100/255 alpha:1.0] forState: UIControlStateNormal];
I have been trying to get the values for Bubblegum to work for a button. This code you posted should work but it doesn't react as expected to the value given for it on
List of colors - Wikipedia, the free encyclopedia .
It just appears as white just wondering if you know off hand why it may not be working.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 259
18 members and 241 guests
14DEV , @sandris , ADY , ArtieFufkin10 , ckgni , Dani77 , HemiMG , IphoneSdk , jakerocheleau , JasonR , MACralik , NSeven , prchn4christ , Rudy , silverwiz , spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp