简体   繁体   中英

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.

在此处输入图片说明

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

if I give equal height. Below is the result

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM