I would like to use a logo as LeftbarButtonItem in an UINavigationController, is it possible to remove the left padding here?
Ill alreay tried:
let logoView = UIView(frame: CGRectMake(-15, 0, 44, 44))
logoView.backgroundColor = UIColor.darkGrayColor()
var leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: logoView)
self.navigationItem.setLeftBarButtonItem(leftBarButtonItem, animated: false)
But thats not working. Ill mean that space shown here in this picture:
Any ideas? Thanks in advance.
Here is the Swift Solution:
let logoView = UIView(frame: CGRectMake(0, 0, 44, 44))
logoView.backgroundColor = UIColor.darkGrayColor()
let negativeSpacer = UIBarButtonItem.init(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
negativeSpacer.width = -20;
let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: logoView)
self.navigationItem.leftBarButtonItems = [negativeSpacer, leftBarButtonItem]
Here's an example of removing the padding to the left of a custom left button item:
UIBarButtonItem *backButtonItem // Assume this exists, filled with our custom view
// Create a negative spacer to go to the left of our custom back button,
// and pull it right to the edge:
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -5;
// Note: We use 5 above b/c that's how many pixels of padding iOS seems to add
// Add the two buttons together on the left:
self.navigationItem.leftBarButtonItems = [NSArray
arrayWithObjects:negativeSpacer, backButtonItem, nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With