Shivbaba's son
Shivbaba's son

Reputation: 1369

Could not trigger bar button item with custom view?

In my iphone application,

I have a one navigation bar Image to set I have set it like this....

   if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){

        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBarReady.png"] forBarMetrics:UIBarMetricsDefault];
    }

    UIBarButtonItem *bbiLeft=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btnBack.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnBackPressed:)]; 
    [bbiLeft setTintColor:[UIColor clearColor]];
    [bbiLeft setBackgroundVerticalPositionAdjustment:7.0f forBarMetrics:UIBarMetricsDefault];
    self.navigationItem.leftBarButtonItem=bbiLeft;

It appears like this...

enter image description here

I want to set its color as navigationbar's background

How?? Thanks..

Upvotes: 2

Views: 789

Answers (2)

Nick Lockwood
Nick Lockwood

Reputation: 40995

Setting the tintColor to clear doesn't work, you should pick a color that matches the bar background.

Also, you may need to set the tintColor of the UINavigationBar, not the tintColor of the UIBarButtonItem itself, as the navigation bar is responsible for tinting it's own button items.

Upvotes: 0

Shivbaba's son
Shivbaba's son

Reputation: 1369

Get the Answer...

/* Back Button setted*/    
    UIButton *btnBack=[UIButton buttonWithType:UIButtonTypeCustom];
    [btnBack addTarget:self action:@selector(btnBackPressed:) forControlEvents:UIControlEventTouchUpInside];
    [btnBack setImage:[UIImage imageNamed:@"btnBack.png"] forState:UIControlStateNormal];
    [btnBack setFrame:CGRectMake(0, 0, 51,16)];
    UIView *backModifiedView=[[UIView alloc] initWithFrame:btnBack.frame];
    [btnBack setFrame:CGRectMake(btnBack.frame.origin.x, btnBack.frame.origin.y+7, btnBack.frame.size.width, btnBack.frame.size.height)];
    [backModifiedView addSubview:btnBack];
    UIBarButtonItem *bbiLeft=[[UIBarButtonItem alloc] initWithCustomView:backModifiedView];
      self.navigationItem.leftBarButtonItem=bbiLeft;



/* Arpit */
//set Navgation Bar.   
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){

        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBarReady.png"] forBarMetrics:UIBarMetricsDefault];
    }

Upvotes: 2

Related Questions