简体   繁体   中英

UINavigationBar titleview image not aligned with the UINavigationBar

My logo was looking to small in the default UINavigationBar, so I increased the height to 67 by overriding

- (CGSize)sizeThatFits:(CGSize)size
{
CGSize newSize = CGSizeMake(self.frame.size.width, 67);
return newSize;
}

I added a 2x image of size 266x130 in the - (void)viewDidLoad using

self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];

But my title logo is not aligned with the NavigationBar.

截图

I just wanted to know why the title view is behaving weird with custom height. I did not have any issue while adding image as title view to the standard UINavigationBar.

Also is this the right way to override UINavigationBar for custom height? Are there any other methods to do the same?

Have you tried this or something like it?

  float positionOffset = ...;
 [UINavigationBar appearance] setTitleVerticalPositionAdjustment:positionOffset forBarMetrics:UIBarMetricsDefault];

There's also this , if that doesn't immediately work.

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