以下是我正在尝试的代码,但没有得到,请任何人知道提前回复
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 :(得分:0)
在doneAction制作按钮Selected
-(void)doneAction:(UIButton *)sender{
sender.selected=true;
}
答案 1 :(得分: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];