Rajesh
Rajesh

Reputation: 10434

Modified navigationbar causes issues on button item

In our project we wanted to change the size of navigationbar. Have achieved it with

@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
    return CGSizeMake(self.superview.bounds.size.width, 55.0f);
}
@end

But the problem here is.. as you would see go button is little down from screen edge. But I wanted it to be in ultimate corner of screen. I use backgroundColor:, setTitle:forState:methods for constructing look of go button. also back button to be vertically middle. How can I achieve that. Tried Using edgeInsets: but no hope.

enter image description here

Edit: Go button height is 10px less than barheight.

if I give equal height. Below is the result

enter image description here

Upvotes: 0

Views: 41

Answers (1)

user3182143
user3182143

Reputation: 9599

in somewhat I have tried your coding.Check that

UIButton *goBtn = [UIButton buttonWithType:UIButtonTypeCustom];
goBtn.frame = CGRectMake(0, 0, 63, 80);
goBtn.backgroundColor = [UIColor redColor];
UIView *goButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 63, 50)];
NSLog(@"goButtonView bounds are - %@", NSStringFromCGRect([goButtonView bounds]));
goButtonView.bounds = CGRectOffset(goButtonView.bounds, -17, 0);
NSLog(@"goButtonView bounds are - %@", NSStringFromCGRect([goButtonView bounds]));
[goButtonView addSubview:goBtn];
UIBarButtonItem *goButton = [[UIBarButtonItem alloc] initWithCustomView:goButtonView];
self.navigationItem.rightBarButtonItem = goButton;

Below the references

Issue with button on the left side of the uinavigation bar

UINavigationBar UIBarButtonItems much larger click area than required

Upvotes: 1

Related Questions