导航栏标题文字不居中

导航栏标题文字不居中,第1张

概述出现部分导航栏标题不居中的原因的上一个视图的title文字过多的情况,引起本页面的返回按钮占居了很多位置将titleview挤到了右边,要解决这个问题,请在viewdidload中设置前一个视图的backBarButtonItem。 为了统一设置:利用了https://github.com/steipete/Aspects这个库注入方法。 方法如下:  [UIViewController aspe

出现部分导航栏标题不居中的原因的上一个视图的Title文字过多的情况,引起本页面的返回按钮占居了很多位置将TitlevIEw挤到了右边,要解决这个问题,请在vIEwdIDload中设置前一个视图的backbarbuttonItem。

为了统一设置:利用了https://github.com/steipete/Aspects这个库注入方法。

方法如下:

[UIVIEwController aspect_hookSelector:@selector(vIEwDIDLoad) withOptions:AspectpositionAfter usingBlock:^(ID<AspectInfo> info) { UIVIEwController* infoVC = (UIVIEwController*)info.instance; NSArray *vIEwControllerArray = [infoVC.navigationController vIEwControllers]; if (vIEwControllerArray == nil) { return ; } long prevIoUsVIEwControllerIndex = [vIEwControllerArray indexOfObject:infoVC] - 1; UIVIEwController *prevIoUs; if (prevIoUsVIEwControllerIndex >= 0 && prevIoUsVIEwControllerIndex < vIEwControllerArray.count) { prevIoUs = [vIEwControllerArray objectAtIndex:prevIoUsVIEwControllerIndex]; if (prevIoUs.Title.length < 4){ return ; } prevIoUs.navigationItem.backbarbuttonItem = [[UIbarbuttonItem alloc] initWithTitle:@"xx" style:UIbarbuttonItemStylePlain target:self action:nil]; } } error:NulL];

总结

以上是内存溢出为你收集整理的导航栏标题文字不居中全部内容,希望文章能够帮你解决导航栏标题文字不居中所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1076117.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存