創建亮狀態的背景圖像編程我創建了一個UIBarButton編程用下面的代碼:爲UIButton的
UIButton * rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
[rightButton setFrame:CGRectMake(0, 0, 81, 30)];
[rightButton setBackgroundColor:[UIColor clearColor]];
rightButton.layer.borderColor = [UIColor blackColor].CGColor;
rightButton.layer.borderWidth = 0.5f;
rightButton.layer.cornerRadius = 5.0f;
rightButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12];
[rightButton setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
[rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//set text according to sign in status
if (signIn) {
[rightButton setTitle:@"5 votes left" forState:UIControlStateNormal];
} else {
[rightButton setTitle:@"Sign in" forState:UIControlStateNormal];
}
UIBarButtonItem * rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightBarButton;
得到的按鈕有希望的方面,但現在我需要的是,當按鈕的狀態突出應該有漸變效果漸變爲黑色,以讓用戶知道他已按下按鈕,因爲現在當我按下按鈕時,視圖沒有任何反應,因此用戶無法知道他已按下按鈕。
我想探索一個選擇,不涉及爲所需的狀態設置背景圖像,因爲按鈕的文本可以根據應用程序配置dinamically更改,所以我需要完全通過代碼完成此操作。我真的不知道如何解決這個問題,所以任何幫助都很樂意接受。