设置导航栏 self.navigationItem.titleView 居中
2024-10-16 14:55:04
喜欢交朋友的加:微信号 dwjluck2013
-(void)viewDidLayoutSubviews{
[self setDisplayCustomTitleText:@"每日头条"];
}
#pragma mark - 设置导航栏 self.navigationItem.titleView 居中
- (void)setDisplayCustomTitleText:(NSString*)text
{
CGFloat titleViewHeight = ;
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(, , Screen_Width, titleViewHeight)];
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin;
titleView.autoresizesSubviews = YES;
titleView.backgroundColor = [UIColor clearColor];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , Screen_Width, titleViewHeight)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont systemFontOfSize:];
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
titleLabel.textColor = kMyColor(, , );
titleLabel.textAlignment = NSTextAlignmentCenter;
CGRect leftViewbounds = self.navigationItem.leftBarButtonItem.customView.bounds;
CGRect rightViewbounds = self.navigationItem.rightBarButtonItem.customView.bounds; CGRect frame;
CGFloat maxWidth = leftViewbounds.size.width > rightViewbounds.size.width ? leftViewbounds.size.width : rightViewbounds.size.width;
maxWidth += ;//leftview 左右都有间隙,左边是5像素,右边是8像素,加2个像素的阀值 5 + 8 + 2
frame = titleLabel.frame;
frame.size.width = Screen_Width - maxWidth * ; titleLabel.frame = frame;
frame = titleView.frame;
frame.size.width = Screen_Width - maxWidth * ;
titleView.frame = frame;
titleLabel.text = text;
[titleView addSubview:titleLabel];
self.navigationItem.titleView = titleView;
}
最新文章
- int.Parse()之异常
- DevExpress VGridControl 行宽自动调整
- Hibernate(一)__简介
- Android存储访问及目录
- Android四大组件之——Activity的生命周期(图文详解)
- JS创建对象、继承原型、ES6中class继承
- ABAP-smartform-一页3列的条码打印
- 【POJ 2823 Sliding Window】 单调队列
- jquery学习(2)--选择器
- 基于MMSeg算法的中文分词类库
- checkbox:全选与反全选
- business expressions(二)
- [iOS]详解调整UIButton的title和image的位置
- ISOMAP
- PowerDesigner 使用教程(很具体,很实用)
- Centos7.5 安装VirtualBox增强工具
- SpringBoot Redis缓存 @Cacheable、@CacheEvict、@CachePut
- java多线程(1)---线程创建、start、run
- flex检查对象是否存在某个方法(函数)、属性的最简方法
- A. 【UR #17】滑稽树上滑稽果
热门文章
- [2017-09-05]Abp系列——Abp后台作业系统介绍与经验分享
- php mcrypt加密实例
- Vue源码探究-状态初始化
- js中const,var,let区别 今天第一次遇到const定义
- python学习笔记:第一天
- hdu 1391 Number Steps(规律)
- Eclipse 插件使用
- python 基础之第十二天(re正则,socket模块)
- java-swing-JTextComponent
- 操作 AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(六)