Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-24-2009, 03:03 PM   #1 (permalink)
iPhone Developer
 
Join Date: Aug 2009
Posts: 64
Post 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.
losingSkillz is offline   Reply With Quote
Old 08-24-2009, 03:37 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

setTitleColor:forState:
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 08-25-2009, 03:47 PM   #3 (permalink)
iPhone Developer
 
Join Date: Aug 2009
Posts: 64
Post

Quote:
Originally Posted by BrianSlick View Post
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.
losingSkillz is offline   Reply With Quote
Old 08-25-2009, 03:51 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

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.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 08-25-2009, 03:52 PM   #5 (permalink)
iPhone Developer
 
Join Date: Aug 2009
Posts: 64
Default

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];
losingSkillz is offline   Reply With Quote
Old 04-23-2010, 10:51 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 11
Default

Quote:
Originally Posted by losingSkillz View Post
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.
superstec is offline   Reply With Quote
Reply

Bookmarks

Tags
button, font color, label, rgb, runtime

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» 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
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:54 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0