我创建一个自定义的UIButton类,并重写了init方法:加入的UIImageView自定义的UIButton类
- (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)];
不知道exaclty为什么我得到这个错误,以及如何解决它。
我需要两个里面。它的两个不同的图像。 – darkman 2013-04-24 23:26:12