我有一個設置放置故事板的UIButton的imageView屬性的方法。它設置後,它看起來很好。但是,輕觸按鈕時,其高亮狀態會將imageView的圖像屬性更改回舊圖像。我如何阻止這種情況發生?這裏是我的方法:如何在按下時阻止UIButton的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];
}
取消註釋所有這三個線 // [profilePhoto setImage的:圖像forState :UIControlStateNormal]; // [profilePhoto setImage:image forState:UIControlStateHighlighted]; // [profilePhoto setImage:image forState:UIControlStateSelected]; 在一起運行,並告訴我發生了什麼 –
它改變了按鈕的背景圖像,而不是像我想要的內部imageView圖像。 – zakdances