Navigation UIBarButtonItem Appearance on device is different

I have a custom bar icon that I am using for my nav controller. I am using the following code in view controllers.

var myImage = UIImage(named: "previous");
UIBarButtonItem.appearance().setBackButtonBackgroundImage(myImage, forState: .Normal, barMetrics: .Default);
let backItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
navigationItem.backBarButtonItem = backItem

      

The result during testing was the following:

Bar back button item during testing

But when my application got into the app store, the result was as follows:

enter image description here

Does anyone know why the result is different and how can I fix the appearance? Or if not, how else can I change the back button element. This is really annoying because my app has a bug that I was not aware of and will take 10 days to update when I find a fix.

UPDATE It seems that if the left element has text, the image is wrapped around the text. However, I used an empty string as I cannot use nil because it uses the default text provided by the navigation controller. So the result is a little packaging of the image.

+3


source to share


1 answer


Try this code:



let backImage = UIImage(named: "BackButton")?.resizableImageWithCapInsets(UIEdgeInsetsMake(0, 25, 0, 0))
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, forState: .Normal, barMetrics: .Default)
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-1000, -1000), forBarMetrics: .Default)

      

0


source







All Articles