Domanda

I am looking for the simple way to set UIButton's default titleColor to custom one at app start. But I want to respect the case, when titleColor is not default and has custom value. [[UIButton appearance] setTitleColor: forState:] allows me to set custom color for all buttons at once. However it overrides already set custom color. Is there any fast way to override default title color and respect custom color at the same time?

È stato utile?

Soluzione

Use appearance as you do for setting global appearance (all buttons) and instance method [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; for setting a color just for one button.

Altri suggerimenti

    Try to this.....

    create catagory class for UIButton like bellow

    Sample.h
    #import <UIKit/UIKit.h>

    @interface Sample : UIButton

    @end

    Sample.m
    #import "Sample.h"

    @implementation Sample
    -(id)initWithCoder:(NSCoder *)aDecoder
    {
        self=[super initWithCoder:aDecoder];
        if (self) {
            [self setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }
        return self;
    }
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        return self;
    }

    @end


    and After crate class use this class as Custom Class Like

![Image][1]


  [1]: http://i.stack.imgur.com/sXYfY.png
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top