如何在iOS中的UITextView中添加多个uibutton

时间:2012-12-15 12:15:06

标签: iphone objective-c ios uibutton uitextview

在我的应用中,我想在UIButton内添加多个UITextView,现在我使用单个对象添加UIButton但我更改任何UIButton更改适用于所有UIButton,我是如何解决的?

-(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;

    myButton=[UIButton buttonWithType:UIButtonTypeCustom];
    myButton.frame=CGRectMake(cursor.x, cursor.y, 15, 15);
    Chkimg = [UIImage imageNamed:@"unchk.png"];
    [myButton setBackgroundImage:Chkimg forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(ChcK) forControlEvents:UIControlEventTouchUpInside];
    [note addSubview:myButton];
}

1 个答案:

答案 0 :(得分:0)

使用button.tag属性区分您的所有按钮。

并可以根据tagValue

执行任务
if(button.tag==0)
{
//do somthing
}
else
{
//do other thing
}