我在視圖內動態創建了一行數字按鈕。點擊任何數字時,我都會突出顯示按鈕。如果我在該行中單擊的次數超過1,則所有單擊的按鈕都會突出顯示。避免多次高亮顯示的操作?如何使用標籤動態創建按鈕動態設置背景圖像?
我已經使用的代碼如下
-(void)pressed:(id)sender{
UIButton *button = (UIButton *)sender;
if(!button.selected){
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(highlightButton:) userInfo:button repeats:NO];
} else {
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(unhighlightButton:) userInfo:button repeats:NO];
}
-(void)highlightButton:(id)sender{
UIButton *button = (UIButton *)[sender userInfo];
button.highlighted = YES;
button.selected = YES;
}
-(void)unhighlightButton:(id)sender{
UIButton *button = (UIButton *)[sender userInfo];
button.highlighted = NO;
button.selected = NO;
}
你如何「突出顯示」按鈕? – 2012-04-25 07:24:11