我一直在試圖讓按鈕的背景色固定在.xib上。就像,默認背景是白色的,但是當按鈕被點擊時,它會變成藍色或黑色,並且它會一直保持到另一個按鈕被點擊。 我做了大部分與UIControlState
,背景顏色和圖像的組合,但似乎沒有任何工作。背景顏色每秒改變一次,並在一秒後進入默認狀態。UIButton在點擊時固定背景色目標C
這是組合的一個我試圖
[self.theButton addTarget:self action:@selector(slideAction:) forControlEvents:UIControlEventTouchUpInside];
-(void) slideAction:(UIButton *)myButton
{
[self.theButton setImage:[UIImage imageNamed:@"blue.png"] forState:UIControlStateNormal];
}
功能的作品,但它不更新的顏色。我不知道這個問題是否與.xib有關。 我很欣賞你能幫助我解決這個問題。 謝謝。
該按鈕點擊
[myButton的了setBackgroundImage:[自imageWithColor:的UIColor綠彩] forState:UIControlStateHighlighted]; //根據您的要求更改狀態和顏色 – nikhil84
查看該帖子https://somethingaboutios.wordpress.com/2016/02/09/uibutton-backgroundcolor-for-uicontrolstateselected/並且這個窗口https://github.com/GabrielMassana/ButtonBackgroundColor-iOS –
我希望我的回答能幫助你。 –