喜欢交朋友的加:微信号 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. Python多线程模块

    引言 thread threading 1 Thread 11 下面使用threading模块实现与上面相同的功能 12 在创建新线程时还可以给Thread传递可调用类的对象这样使用类本身来保存信息 ...

  2. android——实现多语言支持

    我们知道,建好一个android 的项目后,默认的res下面 有layout.values.drawable等目录.这些都是程序默认的资源文件目录,如果要实现多语言版本的话,我们就要添加要实现语言的对 ...

  3. HDU6025 Coprime Sequence —— 前缀和 & 后缀和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6025 Coprime Sequence Time Limit: 2000/1000 MS (Java/ ...

  4. Android5.0 CheckBox颜色修改

    Android5.0开始,CheckBox带有material design动画效果,其默认的样式如下图所示: 可以看到,在上图中,CheckBox的边框为灰色,当被选中后,填充色为绿色. 那么如果我 ...

  5. 网页上传FLV视频文件

    上传 flv格式文件一致提示文件类型不允许,是因为CI中的配置文件没有支持这个格式 在 application/config/mimes.php中加入 'flv' => array('video ...

  6. 网络流量分析——NPMD关注IT运维、识别宕机和运行不佳进行性能优化。智能化分析是关键-主动发现业务运行异常。科来做APT相关的安全分析

    科来 做流量分析,同时也做了一些安全分析(偏APT)——参考其官网:http://www.colasoft.com.cn/cases-and-application/network-security- ...

  7. python库学习笔记——分组计算利器:pandas中的groupby技术

    最近处理数据需要分组计算,又用到了groupby函数,温故而知新. 分组运算的第一阶段,pandas 对象(无论是 Series.DataFrame 还是其他的)中的数据会根据你所提供的一个或多个键被 ...

  8. C语言文件读写总结

    主要有四种: 1.文件的字符输入输出函数 fgetc fputc2.文件的字符串输入输出函数 fgets fputs3.文件的格式化输入输出函数 fscanf fprintf4.文件的数据块输入输出函 ...

  9. [转]VC++中操作XML(MFC、SDK)

    XML在Win32程序方面应该没有在Web方面应用得多,很多Win32程序也只是用XML来存存配置信息而已,而且没有足够的好处的话还不如用ini.VC++里操作XML有两个库可以用:MSXML和Xml ...

  10. HDU1150(最小顶点覆盖)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...