0
votes

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

And the tint color should be : 00ACC1

Please help me to do

I need like this image:

enter image description here

2

2 Answers

2
votes

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];
1
votes

In your Appdelegate set Bar tint:

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

  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;