我创建了一个自定义 UIButton 类并覆盖了 init 方法:
- (id)initWithFrame:(CGRect)frame title:(NSString *)titulo
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
setaDown = [UIImage imageNamed:@"setaDown"];
separator = [UIImage imageNamed:@"separatorLine"];
self = [UIButton buttonWithType:UIButtonTypeCustom];
[self setFrame:frame];
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
seta = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-setaDown.size.width*2, frame.size.height/2, setaDown.size.width/1.2, setaDown.size.height/1.2)];
[seta setImage:setaDown];
[self addSubview:seta];
separatorLine = [[UIImageView alloc]initWithFrame:CGRectMake(5, frame.size.height-2, frame.size.width-10, separator.size.height)];
[separatorLine setImage:separator];
[self addSubview:separatorLine];
[self setTitle:titulo forState:UIControlStateNormal];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
问题是,图像没有显示在按钮中,并且我exc_bad_access
在该行中有一个 , :
seta = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-setaDown.size.width*2, frame.size.height/2, setaDown.size.width/1.2, setaDown.size.height/1.2)];
不知道为什么我得到这个错误,以及如何解决它。