Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change UILabel's text color for total project

i want to change all the UILabel's text color for total app how can i do this .is there any simple way to change label color.

i tried this ,but i want to change write this code in every class

for( UIView *view in [testScroll subviews])
    {
        if([view isKindOfClass:[UILabel class]])
        {
            [(UILabel *)view setTextColor:[UIColor whiteColor]];

        }
        else if([view isKindOfClass:[UIView class]])

    }

Do anyone have simple method .

like image 768
user2197875 Avatar asked Jun 05 '13 10:06

user2197875


2 Answers

Well if you're targeting iOS 5+ you could do that really easy (inside you appdelegate):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //...

    //This color will affect every label in your app
    [[UILabel appearance] setTextColor:[UIColor redColor]]; 

    //...

    return YES;
}

This works because UILabel conforms to UIAppearance protocol, so you could customize any class that conforms to the protocol like this. For more information on this here is a nice tutorial to get you started and here is Apple's docs on the protocol

like image 88
Alladinian Avatar answered Oct 31 '22 16:10

Alladinian


@interface CustomLabel : UILabel
 @end

 @implementation CustomLabel

 - (id)init{
  if ([super init]){
      self.textColor = // Putt here the color you want.
  }

   return self;
 }

and now jus use your CustomLabel.

like image 30
samir Avatar answered Oct 31 '22 17:10

samir