1 //创建一个可以显示图片的按钮。 2 -(void)creatImageBtn{ 3 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 4 btn.frame = CGRectMake(100, 100, 100, 100); 5 UIImage *icon1 = [UIImage imageNamed:@"icon1.png"]; 6 UIImage *icon2 = [UIImage imageNamed:@"icon2.png"]; 7 [btn setImage:icon1 forState:UIControlStateNormal]; 8 [btn setImage:icon2 forState:UIControlStateHighlighted]; 9 [self.view addSubview:btn]; 10 } 11