做项目的过程中发现,IOS的SDK中并没有单选框控件。所以想办法将UIButton自定义成checkbox.方法如下
UIImage *uncheckedImg=[UIImage imageNamed:@"check_2x.png"];
UIImage *checkedImg=[UIImage imageNamed:@"checked_2x.png"];
UIButton *checkboxBtn=[UIButton buttonwithType:UIButtonTypeCustom];
[checkboxBtn setBackgroundImage:uncheckedImg forState:UIControlStateNormal];
[checkboxBtn setBackgroundImage:checkedImg forControl:UIControlStateSelected];
[checkboxBtn addTarget:self action:@selector(chooseBox1:) forControlEvents:UIControlEventTouchupInside];
粗体字部分一定要实现,否则不会有按下button打勾的效果