So, this is what I'm trying to accomplish:
It's a UINavigationBar
with a UIBarButtonItem
that gets initialized with a custom UIButton
.
Basically like this:
UIButton *favoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[favoriteButton addTarget:target
action:action
forControlEvents:UIControlEventTouchUpInside];
favoriteButton.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
UIImage *backgroundImage = [[UIImage imageNamed:@"favorite-button-background-orange"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 0)];
[favoriteButton setBackgroundImage:backgroundImage
forState:UIControlStateNormal];
UIBarButtonItem *favoriteButtonItem = [[UIBarButtonItem alloc] initWithCustomView:favoriteButton];
The problem is I can't seem to get rid of that nasty little border on the right hand side of the UINavigationBar
.
I tried setting a custom TitleView
as described in "How to remove padding next to a UIBarButtonItem" but this didn't change a thing.
I also tried adding another UIBarButtonItem with a negative width (as suggested in some blogposts I read) but that didn't help either.
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
negativeSpacer.width = -5.0f;
self.navigationItem.rightBarButtonItems = %[favoriteButtonItem, negativeSpacer];
I assume iOS won't let me change it because the "rounded border" reserves some (unavoidable?) space / padding?
So my question is. How should I work around this limitation? Do I need to create a custom UINavigationBar
class? Can I fake it somehow by modifying the UIBarButtonItem
? Am I just using the wrong component?