我有一个设置放置故事板的UIButton的imageView属性的方法。设置好之后,看起来不错。但是,当点击该按钮时,其高亮状态会将imageView的image属性更改回旧图像。如何阻止这种情况的发生?这是我的方法:
- (void)setThumbButtonPhoto:(UIImage *)image
{
// profilePhoto is an IBOutlet property of class UIButton pointing to the
// UIButton on my storyboard.
// Button image is changed correctly here
profilePhoto.imageView.image = image;
// But then mysteriously changed back to the old image when tapped.
// The following commented out lines I have all tried (one at a time of course)
// and none have solved my problem -->
// [profilePhoto.imageView setHighlightedImage:nil];
// profilePhoto.imageView.highlightedImage = image;
// profilePhoto.adjustsImageWhenHighlighted = NO;
// [profilePhoto setBackgroundImage:image forState:UIControlStateHighlighted];
// [profilePhoto setImage:image forState:UIControlStateNormal];
// [profilePhoto setImage:image forState:UIControlStateHighlighted];
// [profilePhoto setImage:image forState:UIControlStateSelected];
}
最佳答案
使用UIImageView来保存图像
并放置一个自定义模式的UIButton,没有文本,没有图像,没有背景;在它下面
关于objective-c - 如何在按下时阻止UIButton的imageView更改?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10863973/