I did this with a UITextField so as not to draw anything strange, but I liked to insert text as Unicode text (Unicode character CHECK MARK (U + 2713)) for NSString: @ "\ u2713".
So in my .h file (implementation of the UITextField protocol 'UITextFieldDelegate'):
UITextField * myCheckBox;
In my view, DidLoad or functions to prepare the user interface:
... myCheckBox = [[UITextField alloc] initWithFrame:aFrame]; myCheckBox.borderStyle = UITextBorderStyleRoundedRect;
Then add an event selector for reating in the touch event and raise the responseSelected event:
... UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkboxSelected)]; [myCheckBox addGestureRecognizer:tapGesture]; ...
Finally, answer this selector
-(void) checkboxSelected { if ([self isChecked]) { // Uncheck the selection myCheckBox.text = @" -"; }else{ //Check the selection myCheckBox.text = @"\u2713"; } }
The 'isChecked' function only checks if the text is a @ "\ u2713" mark. To prevent the keyboard from showing when selecting a text field, use the UITextField event 'textFieldShouldBeginEditing' and add an event selector to control the selection:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { // Question selected form the checkbox [self checkboxSelected]; // Hide both keyboard and blinking cursor. return NO; }
mTouch Oct 07 '14 at 11:13 2014-10-07 11:13
source share