OGeek|极客世界-中国程序员成长平台

标题: iOS 11 导航栏搞砸了 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:52
标题: iOS 11 导航栏搞砸了

iOS 11 导航栏的标题 View 和栏按钮项目不居中。 背景图像的高度也没有变化,也没有完整显示。条形高度为74。

enter image description here 查看空白区域。

我试过了

if(@available(iOS 11,*)){
    _homeNavigationBar.prefersLargeTitles = NO;
    _homeNavigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
    [_homeNavigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed"navbarBg.png"]]];
}
else{
    [_homeNavigationBar setBackgroundImage:[UIImage imageNamed"navbarBg.png"] forBarMetrics:UIBarMetricsDefault];
}

但我仍然无法将标题和栏按钮项居中。

知道如何解决这个问题吗?请告诉我。谢谢



Best Answer-推荐答案


子类化导航栏对我有用。

- (void)layoutSubviews {
[super layoutSubviews];

for (UIView *view in self.subviews) {
    if([NSStringFromClass([view class]) containsString"Background"]) {
        view.frame = self.bounds;
    }
    else if ([NSStringFromClass([view class]) containsString"ContentView"]) {
        CGRect frame = view.frame;
        frame.origin.y = 25;
        view.frame = frame;
    }
 }
}

关于iOS 11 导航栏搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46523085/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4