开发者

how to set image in button

How set image in bu开发者_开发知识库tton when ever click the button image show me that button run.backgroundColor = [UIColor redColor] I try this but it doesn't work,


To set an image for a button while it is currently being touched (I think this is what you're asking). You use setImage: forState on the UIButton.

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

You can control when the image appears using the different control states, one of:

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'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜