0

ストーリーボードに配置された 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];
}
4

2 に答える 2

2

ボタンに画像を適切に設定するには、次のメソッドを使用する必要があります。 - (void)setImage:(UIImage *)image forState:(UIControlState)state

そう:

[profilePhoto setImage:image forState:UIControlStateNormal];
[profilePhoto setImage:image forState:UIControlStateHighlighted];
于 2012-06-02T16:25:58.297 に答える
0

UIImageView を使用して画像を保持する

カスタムモードのUIButton、テキストなし、画像なし、背景なしを配置し​​ます。それの下に

于 2012-06-02T16:21:40.510 に答える