iOS - UINavigationItem 的titleView显示不出来的解决方案
2017-12-14 14:08
399 查看
有这样一个需求,就是一个页面的顶部title需要是两行,上边是产品名称,下边是产品code,并且名称和code是不同的字号
查看UINavigationItem的关于title的接口和属性:
![](https://img-blog.csdn.net/20171214140322356?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaWNlZmlzaGxpbHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
其中,title已经不能满足我的需求了,就用titleView
开始我的布局是用masonry布局的,制作了一个容器view,其中放了两个UIlabel,用masonry布局,但是容器view并没有布局,在iPhoneX的模拟器上是可以的,显示都征程,但是在真机上显示不出来,于是我做了如下:
其中减去的80,是给UINavigationItem的left和right留的位置
问题解决了!
查看UINavigationItem的关于title的接口和属性:
其中,title已经不能满足我的需求了,就用titleView
开始我的布局是用masonry布局的,制作了一个容器view,其中放了两个UIlabel,用masonry布局,但是容器view并没有布局,在iPhoneX的模拟器上是可以的,显示都征程,但是在真机上显示不出来,于是我做了如下:
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-80, 44)]; titleView.backgroundColor = [UIColor clearColor]; UILabel *topLabel = [[UILabel alloc] init]; topLabel.text = self.navigationItem.title; topLabel.font = kFT4; topLabel.textColor = kCL1; topLabel.numberOfLines = 1; UILabel *bottomLabel = [[UILabel alloc] init]; bottomLabel.font = kFT0; bottomLabel.textColor = kCL1; bottomLabel.text = self.code; [titleView addSubview:topLabel]; [titleView addSubview:bottomLabel]; [topLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(titleView); make.top.equalTo(titleView).offset(3); }]; [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(titleView); make.top.equalTo(topLabel.mas_bottom); make.bottom.equalTo(titleView).offset(-3); }]; self.navigationItem.titleView = titleView;关键是:
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-80, 44)];
其中减去的80,是给UINavigationItem的left和right留的位置
问题解决了!
相关文章推荐
- iOS拦截webView的Alert与Confirm并让地址不显示,iOS隐藏(或重写)webView弹出提示的title,http:xxx.xx
- iOS拍照 相册选取 保存PNG图片到Documents下,并利用UICollectionView显示出来
- IOS让返回按钮显示自定义标题而不是上个ViewController的title
- iOS - UIScrollView 显示出来后 偏移64的问题
- iOS开发-SDWebImage4.0之后加载gif不显示的解决方案(FLAnimatedImageView FLAnimatedImage)
- IOS UINavigationController的下级页面(子页面)更改titleView不显示的问题
- ios开发中WKWebView在iOS11.0上部分链接显示不出来
- iOS 真机上 webview获取html的title无法显示在navigationBar上。title被挤压。解决
- iOS WKWebView中显示进度条及HTML的title
- IOS webview iframe 宽度超出屏幕解决方案
- iOS 中使用tableView实现右滑显示选择功能
- iOS设置UITableView的背景图片,以及不显示多余的空Cell
- android textView多出来的text不显示省略号
- iOS定位定不出来解决方案
- Android中WebView显示flash闪白屏解决方案
- 【ios】UITableView中的uitablviewcell在64位下显示重叠问题
- IOS开发-UI学习-根据URL显示图片,下载图片的练习(button,textfield,image view,url,data)
- 怎么在图片窗口后台要增加alt 标签和 title 标签输入框。并在栏目页面alt 标签和 title 标签显示出来?
- iOS 判断View 是否是第一次显示
- iOS UIAlertView显示不出标题,及重写系统方法