我正在UIButton
创建一个简单的复选框行为。这是代码:
#import "RadioButton.h"
@implementation RadioButton
@synthesize isSelected;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self ChangeButtonState];
}
-(void)ChangeButtonState{
if (!isSelected) {
isSelected = YES;
[self setBackgroundImage:[UIImage imageNamed:@"radiobtn_on.png"] forState:UIControlStateNormal];
}
else{
isSelected = NO;
[self setBackgroundImage:[UIImage imageNamed:@"radiobtn_off.png"] forState:UIControlStateNormal];
}
}
-(id)init{
self.adjustsImageWhenHighlighted=YES;
self.alpha = 1;
[self ChangeButtonState];
isSelected = NO;
[self setBackgroundImage:[UIImage imageNamed:@"radiobtn_off.png"] forState:UIControlStateNormal];
return self;
}
- (id)initWithFrame:(CGRect)frame
{
[self setBackgroundImage:[UIImage imageNamed:@"radiobtn_off.png"] forState:UIControlStateNormal];
isSelected = NO;
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
首先,当我在启动应用程序时将界面生成器中的类设置为一个按钮时,我没有看到任何东西,直到我点击了这个不可见的按钮。
第二件事是图像看起来比原始图像暗
帮助会很棒!谢谢!