设置导航栏 self.navigationItem.titleView 居中
喜欢交朋友的加:微信号 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 居中的更多相关文章
- 【转】iOS中设置导航栏标题的字体颜色和大小
原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...
- iOS中设置导航栏标题的字体颜色和大小
iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...
- 【iOS开发-22】navigationBar导航栏,navigationItem建立:获取导航栏中的基本文本和button以及各种跳跃
(1)navigationBar导航栏可以被看作是self.navigationController一个属性导航控制器,它可以由点直接表示self.navigationController.navig ...
- 美团HD(2)-设置导航栏内容
DJHomeViewController.m #import "DJHomeViewController.h" #import "DJConstantValue.h&qu ...
- IOS 设置导航栏
//设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...
- iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)
一.UI_APPEARANCE_SELECTOR 彩票项目中appearance的用法一直没有搞明白,这次通过第二个项目中老师的讲解,更深一层次的了解到了很多关于appearance的作用以及使用方法 ...
- iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...
- 设置导航栏nav全透明
设置导航栏nav全透明 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ffffff } span.s1 { } ...
- IOS设置导航栏字体大小及颜色
方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...
随机推荐
- Adjusting Network Connection
Adjusting Network Connection The Selenium Mobile JSON Wire Protocol Specification supports an API fo ...
- Codeforces Beta Round #96 (Div. 1) C. Logo Turtle —— DP
题目链接:http://codeforces.com/contest/132/problem/C C. Logo Turtle time limit per test 2 seconds memory ...
- 【转载】Android进程保活招式大全
原文地址:http://dev.qq.com/topic/57ac4a0ea374c75371c08ce8 目前市面上的应用,貌似除了微信和手Q都会比较担心被用户或者系统(厂商)杀死问题.本文对 An ...
- Object.prototype.constructor
Returns a reference to the Object function that created the instance's prototype. 注意这个属性的值是函数本省的引用,而 ...
- linux安装netcat 运行udp服务器
liunx下安装netcat 1.下载安装包 wget https://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1. ...
- 51Nod - 1055:最长等差数列 (求最长的等差数列)
N个不同的正整数,找出由这些数组成的最长的等差数列. 例如:1 3 5 6 8 9 10 12 13 14 等差子数列包括(仅包括两项的不列举) 1 3 5 1 5 9 13 3 6 9 12 ...
- 记录ubuntu16.04版本安装过程中遇到的问题
记录ubuntu16.04版本安装和使用过程中遇到的些问题,方便以后查看,主要内容有: 1. ubuntu源替换 2. windows与vmware ubuntu文件夹共享 3. putty连接ubu ...
- JVM介绍(一)
JVM是运行在操作系统之上的,它与硬件没有直接的交互 类装载器ClassLoader 负责加载class文件,class文件在文件开头有特定的文件标示,并且ClassLoader只负责class文件的 ...
- sybase SQL记录
在一个表中复制一行,主键是MLID ';
- 评判云服务靠谱程度 -- Coding 安全那些事
本文依据孙宇聪在 SegmentFault D-Day 北京场的演讲内容整理,并授权首发于“高效运维”公众号.10月11日,SegmentFault 将在上海举办D-Day,围绕 Docker 主题. ...