我搜索了一些教程以将 UIImage 添加到单击事件的按钮。如何添加 URL 路径
图像到按钮..例如代码:
UIButton *imageView=[[UIButton alloc]initWithFrame:CGRectMake((320*index)+countFlag*80+ 2, 5, 75, 75)];
imageView.tag=i+1;
[imageView addTarget:self action:@selector(imageViewClicked:) forControlEvents:UIControlEventTouchUpInside];
[imageView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
[imageView.layer setBorderWidth:1.0f];
switch ((i+1)%5) {
case 0:
[imageView setImage:[UIImage imageNamed:@"img1.png"] forState:UIControlStateNormal];
break;
case 1:
[imageView setImage:[UIImage imageNamed:@"img2.png"] forState:UIControlStateNormal];
break;
}