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

设置导航栏 self.navigationItem.titleView 居中的更多相关文章

  1. 【转】iOS中设置导航栏标题的字体颜色和大小

    原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...

  2. iOS中设置导航栏标题的字体颜色和大小

    iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...

  3. 【iOS开发-22】navigationBar导航栏,navigationItem建立:获取导航栏中的基本文本和button以及各种跳跃

    (1)navigationBar导航栏可以被看作是self.navigationController一个属性导航控制器,它可以由点直接表示self.navigationController.navig ...

  4. 美团HD(2)-设置导航栏内容

    DJHomeViewController.m #import "DJHomeViewController.h" #import "DJConstantValue.h&qu ...

  5. IOS 设置导航栏

    //设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...

  6. iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)

    一.UI_APPEARANCE_SELECTOR 彩票项目中appearance的用法一直没有搞明白,这次通过第二个项目中老师的讲解,更深一层次的了解到了很多关于appearance的作用以及使用方法 ...

  7. iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)

                      #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...

  8. 设置导航栏nav全透明

    设置导航栏nav全透明 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ffffff } span.s1 { } ...

  9. IOS设置导航栏字体大小及颜色

    方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...

随机推荐

  1. Algorithm: Euler function

    欧拉函数. phi(n)表示比n小的与n互质的数的个数,比如 phi(1) = 1; phi(2) = 1; phi(3) = 2; phi(4) = 2; phi(5) = 4; 性质: 1. 如果 ...

  2. Android studio在ubuntu下安装【转】

    本文转载自:http://www.jianshu.com/p/776e3b52e930 这学期的Android课程要学Android比较底层的东西,所以老师要求在Linux下安装Android的开发环 ...

  3. Windows Server 2012 修改桌面图标

    在virtualbox 4.2.18中装了个Windows Server 2012 来体验下,结果发现桌面图标都不知道在哪改.在百度文库上找到了解决方法:http://wenku.baidu.com/ ...

  4. html5--3.18 新增的output元素

    html5--3.18 新增的output元素 学习要点 了解output元素的用法 output元素:数据的输出 output元素是HTML5新增的元素,用来设置不同数据的输出 output元素的输 ...

  5. 脚踏实地学C#1-基元类型

    基元类型:编译器直接支持的数据类型 基元类型直接映射到FCL类库上,如int 和Int32是等价的,只不过是int是c#提供的,Int32是FCL类库提供的. int只是Int32的别名 using ...

  6. cuda 版本查阅

    查看cuda版本 cat  /usr/local/cuda/version.txt nvcc -V

  7. SQL Server 2008将数据导出为脚本 [SQL Server]

    之前我们要将一个表中的数据导出为脚本,那么只有在网上找一个导出数据的Script,然后运行就可以导出数据脚本了.现在在SQL Server 2008的Management Studio中增加了一个新特 ...

  8. 改变静态文本框和PictureControl的背景颜色

    /************************************************************************/ /* 改变静态文本框和选择框的背景颜色 */ /* ...

  9. Lombok减少代码冗余量

    Eclipse需要安装,具体用法见: https://projectlombok.org/ 用maven project的朋友,一定要记得安装到IED里面才能使用,不然无法直接使用哦 从此以后和get ...

  10. CodeForces - 566D Restructuring Company 并查集的区间合并

    Restructuring Company Even the most successful company can go through a crisis period when you have ...