我想创建五个具有相同格式的按钮,这样我就为UIButton创建了UICategory类,但我没有得到那个类别类的调用,请帮我解决这个问题,
我的类别类如下,
@implementation UIButton (headerBtn)
+(UIButton *)headerButtons{
UIButton *header = [[UIButton alloc]init];
[header setTitleColor:[UIColor headerBtnColor] forState:UIControlStateNormal];
header.titleLabel.font = [UIFont fontWithName:Fonts_ProximaNovaMedium size:13.0f];
return header;}
正在调用按钮,如下所示
btn_pulse = [UIButton headerButtons];
是正确的方法吗?
答案 0 :(得分:1)
更改行:
UIButton *header = [[UIButton alloc]init];
代表
UIButton *header = [UIButton buttonWithType:UIButtonTypeCustom];
无论如何,我认为你不需要一个类方法。我会这样做:
@implementation UIButton (headerBtn)
-(void)headerStyle{
[self setTitleColor:[UIColor headerBtnColor] forState:UIControlStateNormal];
self.titleLabel.font = [UIFont fontWithName:Fonts_ProximaNovaMedium size:13.0f];
}
您只需要导入您的类别并:
UIButton *myButton = [[UIButton buttonWithType:UIButtonTypeCustom] headerStyle];
答案 1 :(得分:-1)
您必须在任何需要的地方导入您的类别:
#import "UIButton+headerBtn.h"