【发布时间】:2015-03-24 21:43:02
【问题描述】:
这是一个简单的自定义按钮示例,它在 IB 中设置为按钮类:
#import "TestButton.h"
@implementation TestButton
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
UIFont * font = [UIFont systemFontOfSize:8];
if ( self.setFont )
self.titleLabel.font = font;
self.titleLabel.textColor = [UIColor redColor];
}
@end
如果 setFont 为 false,即字体不变,则标签文本颜色为预期的红色。但如果是真的,按钮文本颜色就是它在 IB 中设置的任何颜色。
所以问题是这里发生了什么,如何更改在 IB 中以编程方式分配的按钮的文本和字体。
如果有人想了解这些特性以及 IBDesignable 有多时髦,请参阅demo project
【问题讨论】:
标签: ios cocoa-touch ibdesignable