我正在尝试创建此检查按钮,然后在我的项目中任何我想要的地方调用该检查按钮,并通过添加应有的图像使其工作,但我什至无法将其发送到 NSLog ......进行测试目的...
下面是按钮 .h 和 .m 文件。以及我正在调用按钮并尝试使用的视图......
CheckButton.h #导入
@interface CheckButton : UIButton {
BOOL _checked;
}
@property (nonatomic, setter=setChecked:) BOOL checked;
-(void) setChecked:(BOOL)check;
@end
检查按钮.m
#import "CheckButton.h"
@implementation CheckButton
@synthesize checked = _checked;
-(id) init {
if (self=[super init]) {
self.checked = NO;
[self addTarget:self action:@selector(setChecked:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
-(void) awakeFromNib {
self.checked = NO;
[self addTarget:self action:@selector(OnCheck:) forControlEvents:UIControlEventTouchUpInside];
}
- (void) setChecked:(BOOL)check{
_checked = check;
if(_checked) {
UIImage *img = [UIImage imageNamed:@"check.png"];
[self setImage:img forState:UIControlStateNormal];
NSLog(@"Checked");
} else {
UIImage *img = [UIImage imageNamed:@"uncheck.png"];
[self setImage:img forState:UIControlStateNormal];
NSLog(@"UnChecked");
}
}
-(void) OnCheck:(id) sender {
self.checked = _checked;
}
@end
GoToBedPopUp.h
#import "CheckButton.h"
@interface GoToBedPopup : PopupContainer{
IBOutlet CheckButton *checkboxButton;
}
// Checkboxes - (CheckButton)
@property (nonatomic, strong) CheckButton *checkHR;
@end
GoToBedPopUp.m
#import "GoToBedPopup.h"
@implementation GoToBedPopup
@synthesize checkHR, checkO2, checkMovement, checkNoise, checkSkinTemp;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
// Checkbox Button
checkHR = [[CheckButton alloc] initWithFrame:CGRectMake(17, 31, 23, 23)];
return self;
}