tag
(1) 您可以根据按钮索引分配 UIButton属性。如果要触发任何事件,您可以通过检查来识别该事件属于哪个按钮tag
。
样本 :
// Initializing some buttons
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.tag = 1;
[button1 addTarget:self
action:@selector(buttonPushed:)
forControlEvents:UIControlEventTouchUpInside];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.tag = 2;
[button2 addTarget:self
action:@selector(buttonPushed:)
forControlEvents:UIControlEventTouchUpInside];
按钮事件选择器:
- (void)buttonPushed:(id)sender {
...
if ([sender tag] == 1) {
// do something after button1 event
} else if () {
// do something after button2 event
}
...
}
(2) 如果您选择使用 HTML,您可以查看CMHTMLView