喜欢交朋友的加:微信号 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;
}

最新文章

  1. int.Parse()之异常
  2. DevExpress VGridControl 行宽自动调整
  3. Hibernate(一)__简介
  4. Android存储访问及目录
  5. Android四大组件之——Activity的生命周期(图文详解)
  6. JS创建对象、继承原型、ES6中class继承
  7. ABAP-smartform-一页3列的条码打印
  8. 【POJ 2823 Sliding Window】 单调队列
  9. jquery学习(2)--选择器
  10. 基于MMSeg算法的中文分词类库
  11. checkbox:全选与反全选
  12. business expressions(二)
  13. [iOS]详解调整UIButton的title和image的位置
  14. ISOMAP
  15. PowerDesigner 使用教程(很具体,很实用)
  16. Centos7.5 安装VirtualBox增强工具
  17. SpringBoot Redis缓存 @Cacheable、@CacheEvict、@CachePut
  18. java多线程(1)---线程创建、start、run
  19. flex检查对象是否存在某个方法(函数)、属性的最简方法
  20. A. 【UR #17】滑稽树上滑稽果

热门文章

  1. [2017-09-05]Abp系列——Abp后台作业系统介绍与经验分享
  2. php mcrypt加密实例
  3. Vue源码探究-状态初始化
  4. js中const,var,let区别 今天第一次遇到const定义
  5. python学习笔记:第一天
  6. hdu 1391 Number Steps(规律)
  7. Eclipse 插件使用
  8. python 基础之第十二天(re正则,socket模块)
  9. java-swing-JTextComponent
  10. 操作 AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(六)