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.
Change UIButton's default titleColor
سؤال
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?
المحلول
نصائح أخرى
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
لا تنتمي إلى StackOverflow