2014-05-06 55 views
0

下面是我試圖,但沒有拿到代碼時定製的UIBarButtonItem不改變,請任何事先知道TEXTCOLOR按

UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem]; 
doneButton.frame = CGRectMake(0.0, 0.0, 48.0, 32.0); 
[doneButton setTitle:@"Done" forState:UIControlStateNormal]; 
[doneButton setTitleColor:[UIColor colorWithRed:37/255.0 green:180/255.0 blue:185/255.0 alpha:1.0] forState:UIControlStateNormal]; 
[doneButton setTitleColor:[UIColor colorWithRed:76.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1.0] forState:UIControlStateHighlighted|UIControlStateSelected]; 
[doneButton.titleLabel setFont:[CSUtilities latoRegularFontForSize:18.0]]; 
[doneButton setBackgroundColor:[UIColor clearColor]]; 
[doneButton addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *doneButtonItem = [[UIBarButtonItem alloc] initWithCustomView:doneButton]; 
self.navigationItem.rightBarButtonItem = doneButtonItem; 
+0

http://stackoverflow.com/questions/21084316/change-the-default-font-of-back-button-in-uinavigationcontroller/21084347#21084347 –

回答

0

發佈答案感謝在doneAction生成按鈕Selected

-(void)doneAction:(UIButton *)sender{ 
sender.selected=true; 

}

0

你不需要添加UIControlStateSelected在你的代碼。僅使用UIControlStateHighlighted

[doneButton setTitleColor:[UIColor colorWithRed:76.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1.0] forState:UIControlStateHighlighted];