UIPickerView BarButton文本颜色不会更改,但是当单击按钮时,目标c中的颜色会更改

时间:2019-01-25 05:41:36

标签: ios objective-c uipickerview uibarbuttonitem

我遇到问题,我将UIPickerView BarButton的标题颜色设置为蓝色,但是它不能提供理想的输出,但是当我单击该按钮时,它给出的输出意味着它将颜色更改为蓝色,但是我不要只在单击后才想蓝色,我要在单击前先把按钮颜色变成蓝色。所以我该怎么做,请帮我解决这个问题。谢谢

enter image description here

代码:-

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

     }

2 个答案:

答案 0 :(得分:1)

我知道这个问题是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

答案 1 :(得分:0)

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

layout.setProgressViewEndTarget(false,0);
layout.setProgressBackgroundColorSchemeColor(R.color.transparent);
layout.setProgressBackgroundColorSchemeResource(R.color.trasparent);