[英]adding Bg for Bar button item and tint color
I have created a bar button item programatically. 我已经以编程方式创建了一个条形按钮项。 Now its looking line simple text .
现在它的外观线条简单。 I need to set Background color without border and also need to set tint color programatically.
我需要设置无边框的背景色,还需要以编程方式设置淡色。 Here is the code i create a bar button item:
这是我创建一个条形按钮项的代码:
UIBarButtonItem *callBtn = [[UIBarButtonItem alloc] initWithTitle:@"Call Me" style:UIBarButtonItemStylePlain target:self action:@selector(signUpButtonTapped:)];
self.navigationItem.rightBarButtonItem = callBtn;
And the background color should: #F9F9F9
并且背景色应为:
#F9F9F9
And the tint color should be : 00ACC1
色调颜色应为:
00ACC1
Please help me to do 请帮我做
I need like this image: 我需要这样的图像:
Use Custom Button for to have custom control Following Code May help 使用自定义按钮进行自定义控制以下代码可能会有所帮助
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(0,0,60,30);
[button setBackgroundColor:[UIColor yourColor]];
[button setTitleColor:[UIColor yourColor] forState:UIControlStateNormal];
[button setTitle:@"Call Me" forState:UIControlStateNormal];
[button addTarget:self action:@selector(navigateToDiscussionScreen) forControlEvents:UIControlEventTouchUpInside];
UIView *view = [[UIView alloc] initWithFrame:button.bounds];
view.backgroundColor = [UIColor clearColor];
[view addSubview:button];
UIBarButtonItem *logoBtn = [[UIBarButtonItem alloc]initWithCustomView:view];
In your Appdelegate set Bar tint: 在您的Appdelegate中设置Bar色调:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIColor *barColor = [UIColor colorWithRed:0 green:172/255.0 blue:193/255.0 alpha:1.0];
[[UINavigationBar appearance]setBarTintColor: barColor];
return YES;
}
Now In your View Controller: 现在在您的View Controller中:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0,0,80,30);
[btn addTarget:self action:@selector(signUpButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
UIColor *barColor = [UIColor colorWithRed:0 green:172/255.0 blue:193/255.0 alpha:1.0];
[btn setTitle:@"Call Me" forState:UIControlStateNormal];
[btn setTitleColor:barColor forState:UIControlStateNormal];
btn.backgroundColor = [UIColor lightGrayColor];
UIBarButtonItem *callBtn =[[UIBarButtonItem alloc]initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = callBtn;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.