嗨我想在按下按鈕後更改我的按鈕的背景,即按鈕不應該變回到先前的圖像。如何設置UIControlStateSelected的按鈕圖像
但是,我無法這樣做。我的代碼如下。任何人都可以建議我點擊按鈕後如何將圖像更改爲「custom_button_highlight」?
UIImage *buttonImageNormal = [UIImage imageNamed:@"custom_button"];
UIImage *stretchableButtonImageNormal = [buttonImageNormal
stretchableImageWithLeftCapWidth:12 topCapHeight:0];
UIImage *buttonImagePressed = [UIImage imageNamed:@"custom_button_highlight"];
UIImage *stretchableButtonImagePressed = [buttonImagePressed
stretchableImageWithLeftCapWidth:12 topCapHeight:0];
button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[button setBackgroundImage:stretchableButtonImageNormal
forState:UIControlStateNormal];
[button setBackgroundImage:stretchableButtonImagePressed
forState:UIControlStateHighlighted];
[button setBackgroundImage:stretchableButtonImagePressed
forState:UIControlStateSelected];
這很棒,很簡單!謝謝! – Jean
Awasome斯里卡:) –
@SharmaVishal謝謝!如果您發現我的回答有幫助,請投票。 –