【发布时间】:2019-01-25 05:41:36
【问题描述】:
我有问题我已将 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 {
}
【问题讨论】:
-
我已经尝试过您的代码并正确显示“完成”按钮。某些东西必须从其他代码中破坏。
-
我在 AppDelegate 中编写了一些代码,我只是在这里更新代码,请检查一下,我不知道为什么会发生这种情况!
-
我也尝试过 appdelegate 代码,这也可以正常工作。必须与其他代码中断。
-
太棒了:)快乐编码!
标签: ios objective-c uipickerview uibarbuttonitem