UIPickerView BarButton 文本颜色没有改变但是当点击按钮时颜色会改变 Objective-C

UIPickerView BarButton Text Color is not change but when click on button then the color is change in Objective-C

我有问题,我已将 UIPickerView BarButton 标题颜色设置为蓝色,但它没有提供完美的输出,但是当我单击该按钮时,它提供了输出意味着它将颜色更改为蓝色但我不想只在点击后显示蓝色,我希望按钮在点击前显示为蓝色。那我该怎么做呢?

代码:

-(void)SetToolbar
{
    //******* add buttons in toolbar
    self.toolbar=[[UIToolbar alloc]init];
    self.toolbar.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin );
    self.toolbar.frame=CGRectMake(0, self.currencypicker.frame.origin.y, self.currencypicker.frame.size.width, 45);
    self.toolbar.barStyle=UIBarStyleDefault;
    self.toolbar.backgroundColor=[UIColor whiteColor];
    self.toolbar.tintColor=[UIColor blueColor];
    UIBarButtonItem *donebutton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Btn_DoneClick)];
    //    donebutton.style=UIBarButtonItemStylePlain;
    UIBarButtonItem *cancelbutton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Btn_CancelClick)];
    UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIView *titleview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 40)];
    titleview.backgroundColor=[UIColor clearColor];
    UILabel *lbltitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 40)];
    lbltitle.backgroundColor=[UIColor clearColor];

    lbltitle.textAlignment=NSTextAlignmentCenter;
    lbltitle.text=@"Payment Type";
    lbltitle.font=[UIFont boldSystemFontOfSize:17.0];
    if(IS_IPAD)
    {
        lbltitle.textColor=[UIColor colorWithRed:113.0/256 green:120.0/256 blue:128.0/256 alpha:1.0];
    }
    else
    {
         lbltitle.textColor=[UIColor blackColor];
    }
    [titleview addSubview:lbltitle];

    UIBarButtonItem *btnAdd=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPaymentClicked)];

    UIBarButtonItem *titlebutton = [[UIBarButtonItem alloc] initWithCustomView:titleview];

    NSArray *items = [NSArray arrayWithObjects:cancelbutton,flex,titlebutton,flex,btnAdd, donebutton, nil];
    [self.toolbar setItems:items animated:NO];
    [self.view addSubview:self.toolbar];
    [self.view bringSubviewToFront:self.pickerView];
    //*******
}

我的委托 DidFinishCode 用于导航:

[[UINavigationBar appearance] setBarTintColor:FooterBGColor];
 [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
 if (@available(iOS 11.0, *)) {
      [[UINavigationBar appearance] setLargeTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
      [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
 } else {

 }

在完成按钮中使用色调颜色 试试这个。

 UIBarButtonItem *donebutton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Btn_DoneClick)];
    //    donebutton.style=UIBarButtonItemStylePlain;
donebutton.tintColor = [UIColor blueColor];

我知道这个问题是 10 个月前提出的。但是今天我仍然有这个问题。我尝试更改色调,但不知道为什么它不起作用。花了几个小时后,我最终决定在 UIToolbar 上创建一个 UIView,然后在其上添加一个 UIButton。它对我有用。我希望它能对以后的人有所帮助。

// UIPickerView
self.myPickerView = UIPickerView(frame:CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 216))
self.myPickerView.delegate = self
self.myPickerView.dataSource = self
self.myPickerView.backgroundColor = UIColor.white
cell.myTextField.inputView = self.myPickerView

// ToolBar
let toolBar = UIToolbar()
toolBar.barStyle = .default
toolBar.isTranslucent = true
toolBar.tintColor = UIColor(red: 92/255, green: 216/255, blue: 255/255, alpha: 1)
toolBar.sizeToFit()

// UIView
let myNewView=UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 44))
myNewView.backgroundColor = .lightGray
toolBar.addSubview(myNewView)

// UIButton
let button:UIButton = UIButton(frame: CGRect(x: myNewView.bounds.width - 80, y: 0, width: 70, height: 44))
button.setTitle("Done", for: .normal)
button.addTarget(self, action:#selector(self.doneClick), for: .touchUpInside)
myNewView.addSubview(button)

cell.myTextField.inputAccessoryView = toolBar