Programming in almost language

This is the site where you may share your knowledge and experience to eachother..

  • Categories

  • LinkedIn

  • Tweet Me

  • My footsteps

UIColor with String

Posted by Praveen Kumar on February 1, 2011

Here, we have a variable called buttonColor which may have any string with color name, for instance “blue”,”black”,”red” and we are going to set the UIButton title color based on buttonColor given


SEL colorSel = NSSelectorFromString([NSString stringWithFormat:@"%@Color", buttonColor]);
UIColor* tColor = nil;
if ([UIColor respondsToSelector:colorSel]){
tColor  = [UIColor performSelector:colorSel];
} else {
tColor = whiteColor;
}
[button setTitleColor:tColor forState:UIControlStateNormal];

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: