我有一个UITextView
在UIViewController
. 在那UITextView
,需要为注释插入多个复选框。
如何创建多个复选框?
I have created Multiple CheckBoxes for `UIButton` Click, But When I Select or DeSelect operation, all ChecKBoxes Value changes.
如何动态创建多个复选框并为这些复选框创建方法?
是否可以?
这是我的代码:
-(void)Check
{
CGPoint origin = note.frame.origin;
NSString* head = [note.text substringToIndex:note.selectedRange.location];
CGSize initialSize = [head sizeWithFont:note.font constrainedToSize:note.contentSize];
NSUInteger startOfLine = [head length];
NSString* tail = [head substringFromIndex:startOfLine];
CGSize lineSize = [tail sizeWithFont:note.font forWidth:note.contentSize.width lineBreakMode:UILineBreakModeWordWrap];
CGPoint cursor = origin;
cursor.x += lineSize.width+15;
cursor.y += initialSize.height - lineSize.height-130;
checkbox = [[UIButton alloc] initWithFrame:CGRectMake(cursor.x,cursor.y,15,15)];
[checkbox setBackgroundImage:[UIImage imageNamed:@"unchk.png"]forState:UIControlStateNormal];
[checkbox setBackgroundImage:[UIImage imageNamed:@"chk.png"]forState:UIControlStateSelected];
[checkbox setBackgroundImage:[UIImage imageNamed:@"chk.png"]forState:UIControlStateHighlighted];
checkbox.adjustsImageWhenHighlighted=YES;
[checkbox addTarget:self action:@selector(ChkUnChk) forControlEvents:UIControlEventTouchUpInside];
[note addSubview:checkbox];
}
-(void)ChkUnChk
{
if(checkUnCheck==NO)
{
[checkbox setBackgroundImage:[UIImage imageNamed:@"chk.png"]forState:UIControlStateNormal];
checkUnCheck=YES;
}
else if(checkUnCheck==YES)
{
[checkbox setBackgroundImage:[UIImage imageNamed:@"unchk.png"]forState:UIControlStateNormal];
checkUnCheck=NO;
}
}
-(void)checkboxSelected:(id)sender
{
checkBoxSelected = !checkBoxSelected;
[checkbox setSelected:checkBoxSelected];
}
这里注意 --> UITextView
,复选框 -->UIButton