-1

私のアプリでは、 のUIButton中に複数を追加したいのですがUITextView、今はUIButton単一のオブジェクトを使用して追加していますが、変更を変更UIButtonして all に適用します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];
}
4

1 に答える 1

0

プロパティを使用button.tagして、すべてのボタンを区別します。

tagValueに従ってタスクを実行できます

if(button.tag==0)
{
//do somthing
}
else
{
//do other thing
}
于 2012-12-15T12:19:08.827 に答える