1

ボタンの画像をクリックしたときにボタンに画像を設定すると、ボタンが実行されることがわかります。backgroundColor= [UIColor redColor]これを試してみましたが、機能しません。

4

1 に答える 1

6

ボタンが現在タッチされているときに画像を設定すること(これがあなたが求めていることだと思います)。UIButtonでsetImage:forStateを使用します。

[myButton setImage:[UIImage imageNamed:@"myButtonGraphic.png"] forState:UIControlStateHighlighted];

次のいずれかの制御状態を使用して、画像がいつ表示されるかを制御できます。

UIControlStateNormal

UIControlStateHighlighted

UIControlStateDisabled

UIControlStateSelected

UIControlStateApplication

UIControlStateReserved

If you use UIControlStateNormal, the image is displayed all the time, and when the button is currently being touched it will appear dimmer which for a lot of cases is good enough to indicate to the user that they are selecting that button and that it's a real touchable 'thing'.

于 2010-07-14T10:21:27.427 に答える