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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 02-08-2012, 03:46 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default Changing font color of UISegmentedControl

I wrote this handy little function to change the font color of a UISegmentedControl and it works perfectly, even having a different foont color depending on the active segment.

The problem is I would rather it be a little more generic in that I am currently looking at the value of the label to determine if the current segment in the loop is the active segment.

when looping through the segments, it doesn't necessarily loop through in order and I can't figure out how to tell if the current segment is the active segment, without checking the name.

Anyone have any ideas on how to tell if a given subview is the active segment subview?

Code:
+(void)setFontColorForSegment:(UISegmentedControl *)segment:(NSArray *)values
{
	
	if(values==nil)
		values = [NSArray arrayWithObjects:@"All", @"Cash Games", @"Tournaments", nil];
	for (id seg in [segment subviews]) {
		for (id label in [seg subviews])
			if([label isKindOfClass:[UILabel class]]) {
				UILabel *temp = label;
				if(![temp.text isEqualToString:[values stringAtIndex:segment.selectedSegmentIndex]]) {
					[label setTextColor:[UIColor colorWithRed:.2 green:.2 blue:.2 alpha:1]];
					[label setShadowColor:[UIColor whiteColor]];
					[label setShadowOffset:CGSizeMake(-1.0, -1.0)];
				} else {
					[label setTextColor:[UIColor whiteColor]];
					[label setShadowColor:[UIColor blackColor]];
					[label setShadowOffset:CGSizeMake(2.0, 2.0)];
				}
			}
		
	}
}
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Reply

Bookmarks

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: 402
14 members and 388 guests
7twenty7, chiataytuday, chits12345, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Leslie80, Matrix23, ryantcb, stanny, xerohuang, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

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