我正在寻找在应用开始时将UIButton's
默认titleColor
设置为自定义的简单方法。但我想尊重这种情况,titleColor
不是默认值并具有自定义值。 [[UIButton appearance] setTitleColor: forState:]
允许我一次为所有按钮设置自定义颜色。但是它覆盖了已经设置的自定义颜色。
有没有快速方法来覆盖默认标题颜色并同时尊重自定义颜色?
答案 0 :(得分:0)
使用appearance
设置全局外观(所有按钮)和实例方法 [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
,仅为一个按钮设置颜色。
答案 1 :(得分:0)
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