我在下面的代码上创建了for循环的一些按钮。带IBAction的IOS UIButton
UIView *buttonsView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _viewEmoji.frame.size.width, 35)];
[buttonsView setBackgroundColor:[UIColor greenColor]];
for (int i = 0; i < myObject.count; i ++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(35*i + 5, 0, 35, 35)];
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@", [myObject objectAtIndex:i]]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
[buttonsView addSubview:button];
}
现在,我如何点击按钮来处理事件。
每个按钮被点击,它将处理1个事件。例如:如果我有2个按钮是由for循环创建的。当我点击按钮1,它会记录1,当我点击按钮2,它会记录2.
每个按钮提供一个独特的'tag'值。 – rmaddy