我有一个方法可以设置故事板放置的 UIButton 的 imageView 属性。设置后,它看起来很好。但是,当点击按钮时,它的高亮状态会将 imageView 的图像属性更改回旧图像。我该如何阻止这种情况发生?这是我的方法:
- (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];
}