我已经创建了一个UIButton的子类来给它一个白色的2px没有半径边框,现在我试图根据按钮状态“全局”设置它的字体,字体颜色和背景颜色。UIButton子类 - 设置属性?
字体未设置。颜色或背景颜色也不一样。这是怎么回事?这是我的代码。我希望你能帮到:)
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[[self titleLabel] setFont:[UIFont fontWithName:@"ZegoeUI" size:18]];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
if(self.state == UIControlStateHighlighted) {
[self setBackgroundColor:[UIColor whiteColor]];
}
else {
[self setBackgroundColor:[UIColor blackColor]];
}
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
[self.layer setMasksToBounds:YES];
[self.layer setBorderWidth:2.0];
[self.layer setCornerRadius:0.0];
[self.layer setBorderColor:[[UIColor colorWithWhite:1.0 alpha:1.0] CGColor]];
}
我不认为我做错了什么。我有这个类,并在IB链接按钮,并设置类的类型......
感谢,
奔奔
我到底该如何去做呢?我从来没有去过大学,这是所有自学成为迄今.. – topLayoutGuide
你和我都:)。查看更新回答 – jrturton