我使用 for 循环创建了 5 个按钮,基于在CGRectMake
. 但是当我单击每个按钮时如何更改按钮的背景颜色?还有标题和每个按钮的警报视图?请建议我回答..
//array taken for button titles
NSArray *array1=[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
int k=0;
for(int i=50;i<=350;i=i+70)
{
button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(30,i,35,40);
[button addTarget:self action:@selector(buttonclicked:) forControlEvents:UIControlEventTouchUpInside];
if (k<[array1 count])
{
[button setTitle:[array1 objectAtIndex:k] forState:UIControlStateNormal];
}
k++;
[self.view addSubview:button];
}