Vanessa
Vanessa

Reputation: 73

iOS > how to remove white marks to the right of custom back button

I want to custom iOS back button throughout the application. So I add these lines in my file AppDelegate.m :

UIImage *backButton = [UIImage imageNamed:@"btn_return"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButton.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

Here is the result : enter image description here

As you can see, there is a white mark on the right.... Does somebody know why ? How can I remove it ?

The previous view controller has a white space as back button title (in his navigation item) because I don't want any label. Maybe it's because of that ?! Is there an other solution to not see the default "Back" label ?

Thanks a lot for your help

[EDIT] When I try the answer of Cy-4AH, I get : enter image description here

Upvotes: 3

Views: 167

Answers (6)

Vanessa
Vanessa

Reputation: 73

Thanks to @DipenPanchasara, I changed my code by :

UIImage *backButtonImage = [[UIImage imageNamed:@"btn_return"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
GFloat leftInset = SYSTEM_VERSION_GREATER_THAN(@"9.0") ? -2.5 : backButtonImage.size.width -12;
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButtonImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, leftInset, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

(values in UIEdgeInsetsMake changed)

Here is the result : enter image description here

The back button image is slightly flattened but it doesn't matter.

Thank you all for your suggestions ! :-)

Upvotes: 0

Vidhi Patel
Vidhi Patel

Reputation: 641

Use this code for hide default backbutton

   self.navigationItem.hidesBackButton = YES;

Upvotes: 0

Gaurav Gudaliya
Gaurav Gudaliya

Reputation: 131

UIButton *backButton;
    backButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0,35 ,35)];
    backButton.imageEdgeInsets = UIEdgeInsetsMake(7, 7, 7, 7);
    [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(btnBackAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:@"your back button image name"] forState:UIControlStateNormal];
    UIBarButtonItem *Rightbarbutton=[[UIBarButtonItem alloc]initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem=Rightbarbutton;

Upvotes: 0

vibhor
vibhor

Reputation: 111

Use this code:

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                     forBarMetrics:UIBarMetricsDefault];

Upvotes: 0

Cy-4AH
Cy-4AH

Reputation: 4585

You need use

[[UINavigationBar appearance] setBackIndicatorImage: backButton];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage: backButton];

if yours deployment target IOS 7+

Otherwise ask yours designer to add one pixel empty column in the right.

Upvotes: 0

Uma Madhavi
Uma Madhavi

Reputation: 4917

Use in this way for

UIImage *image1 = [[UIImage imageNamed:@"btn_return"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[self.menuBarBtn setImage:image1];

Upvotes: 2

Related Questions