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-09-2009, 05:48 AM   #1 (permalink)
Registered Member
 
Frankie's Avatar
 
Join Date: Jun 2009
Location: San Antonio, TX
Posts: 104
Send a message via MSN to Frankie
Talking Changing Color of Labels Help

How do I change the color of a Label when it reaches a certain point?

I have this equation and the Label switches to the answer. But when the answers reaches certain points I want the label to change color. How do I go about doing so?
__________________
My new app that was recently featured in the App Store section: Soundsations
Creator of the most awesome app iWasted
Also Created the Audience app

Last edited by Frankie; 08-09-2009 at 05:53 AM.
Frankie is offline   Reply With Quote
Old 08-09-2009, 10:14 AM   #2 (permalink)
Registered Member
 
rdominelli's Avatar
 
Join Date: Jul 2009
Posts: 107
Default

Quote:
Originally Posted by Frankie View Post
How do I change the color of a Label when it reaches a certain point?

I have this equation and the Label switches to the answer. But when the answers reaches certain points I want the label to change color. How do I go about doing so?
UILabel *mylabel; // Connected in IB to a field on the form.

When the state reaches the time you want to change the color on

[mylabel setTextColor:[UIColor redColor]]; // Foreground color
[mylabel setBackgroundColor:[UIColor redColor]]; // Background color

Check the api docs for the other color values and how to roll your own.


Hope this helps.
Rich
rdominelli is offline   Reply With Quote
Old 08-09-2009, 03:11 PM   #3 (permalink)
Registered Member
 
Frankie's Avatar
 
Join Date: Jun 2009
Location: San Antonio, TX
Posts: 104
Send a message via MSN to Frankie
Default

Quote:
Originally Posted by rdominelli View Post
UILabel *mylabel; // Connected in IB to a field on the form.

When the state reaches the time you want to change the color on

[mylabel setTextColor:[UIColor redColor]]; // Foreground color
[mylabel setBackgroundColor:[UIColor redColor]]; // Background color

Check the api docs for the other color values and how to roll your own.


Hope this helps.
Rich
So if I have this.
Code:
float tipTotal = tipSelected * 3.8 / [billTotal.text floatValue];
tipAmount.text = [NSString stringWithFormat:@"Tip Percentage: %.2f%", tipTotal];
How do i get it to change to red every time it reaches 20 and up but remain green only on 1-19?

Also thanks for the reply Rich!
__________________
My new app that was recently featured in the App Store section: Soundsations
Creator of the most awesome app iWasted
Also Created the Audience app
Frankie is offline   Reply With Quote
Old 08-09-2009, 04:37 PM   #4 (permalink)
Registered Member
 
rdominelli's Avatar
 
Join Date: Jul 2009
Posts: 107
Default

Quote:
Originally Posted by Frankie View Post
So if I have this.
Code:
float tipTotal = tipSelected * 3.8 / [billTotal.text floatValue];
tipAmount.text = [NSString stringWithFormat:@"Tip Percentage: %.2f%", tipTotal];
How do i get it to change to red every time it reaches 20 and up but remain green only on 1-19?

Also thanks for the reply Rich!
Assuming tipAmount is your label.

if (tipTotal > 20)
{
[tipAmount setTextColor:[UIColor redColor]];
}

You might need to also do
[tipTotal setNeedsDisplay];

To make sure the color change is shown. This will force a repaint of the label.

Rich
rdominelli is offline   Reply With Quote
Old 08-09-2009, 05:05 PM   #5 (permalink)
Registered Member
 
Frankie's Avatar
 
Join Date: Jun 2009
Location: San Antonio, TX
Posts: 104
Send a message via MSN to Frankie
Default

Quote:
Originally Posted by rdominelli View Post
Assuming tipAmount is your label.

if (tipTotal > 20)
{
[tipAmount setTextColor:[UIColor redColor]];
}

You might need to also do
[tipTotal setNeedsDisplay];

To make sure the color change is shown. This will force a repaint of the label.

Rich
That did it! Thanks Rich.
__________________
My new app that was recently featured in the App Store section: Soundsations
Creator of the most awesome app iWasted
Also Created the Audience app
Frankie is offline   Reply With Quote
Reply

Bookmarks

Tags
calculation, change, color, font, label

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: 270
20 members and 250 guests
@sandris, AdamL, ADY, Dani77, diyora, FAED, F_Bryant, GHuebner, HDshot, headkaze, mer10, Oral B, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,749
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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