我有一個UIButton,我需要點擊按鈕時更改按鈕的圖像。 Button的背景圖像在ViewDidLoad方法中設置。請參考附在這個線程上的圖片。UIButton:背景圖像設置按鈕狀態高亮顯示時的問題?
- 當我第一次點擊按鈕時,按鈕屬性將被改變爲選中,並且「arrow_right.png」圖片將被設置爲我們的按鈕。
2.1936第二抽頭,我觀察到,當按鈕狀態被高亮顯示,但它的背景圖像不被設置。你可以看到一些模糊效果。
我擔心的是我看到了,而切換的UIButton,圖片是沒有得到設置高亮狀態。當按鈕的狀態從「選定」更改爲「正常」時。 這是一個錯誤還是我的錯誤?
謝謝。
- (void)viewDidLoad
{
[super viewDidLoad];
[testButton setBackgroundImage:[UIImage imageNamed:@"btn_normal.png"] forState:UIControlStateNormal];
[testButton setBackgroundImage:[UIImage imageNamed:@"btn_pressed.png"] forState:UIControlStateSelected];
[testButton setBackgroundImage:[UIImage imageNamed:@"btn_pressed.png"] forState:UIControlStateHighlighted];
}
- (IBAction)buttonPressed:(id)sender
{
UIButton *button = (UIButton*)sender;
button.selected = !button.selected;
if (button.selected)
{
[button setImage:[UIImage imageNamed:@"arrow_right.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"arrow_right.png"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"arrow_right.png"] forState:UIControlStateSelected];
}
else
{
[button setImage:[UIImage imageNamed:@"arrow_left.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"arrow_left.png"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"arrow_left.png"] forState:UIControlStateSelected];
}
}
什麼是問題? – TheTiger 2012-07-30 10:50:49
抱歉frd,我在編輯我的帖子。對不起,你說服了。 – 2012-07-30 11:22:30