1

I have issue I have set UIPickerView BarButton title color to blue but it not give the perfect output but when I click on that button it gives the output means it change the color to blue but I don't want blue color only after click, I want button color blue before click. so how can I do this?

enter image description here

Code:

-(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];
    //*******
}

My Delegate DidFinishCode For Navigation:

[[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 {

 }
13

2 Answers 2

1

I know this question was asked 10 months ago. But today I still had this issue. I tried changing tint color and I have no idea why it is not working. After spending hours, I finally decided to create a UIView on UIToolbar and then add a UIButton on it. It worked for me. I hope it might help someone in future.

// 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
0

use tint Color in Donebutton try This.

 UIBarButtonItem *donebutton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Btn_DoneClick)];
    //    donebutton.style=UIBarButtonItemStylePlain;
donebutton.tintColor = [UIColor blueColor];
2
  • let tool = UIToolbar();tool.barStyle = UIBarStyle.default tool.isTranslucent = true tool.tintColor = UIColor.blue tool.sizeToFit() tool.barTintColor = UIColor.blue tool.backgroundColor = UIColor.white // this is swift code i hope you convert in objective c. Jan 25, 2019 at 6:23
  • I try this code still is not working @Pradip i think we missed something !! Jan 25, 2019 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.