iOS 设置titleview的宽度为屏幕宽
来源:互联网 发布:switch case用法 java 编辑:程序博客网 时间:2024/05/01 14:37
项目中,需要使用self.navigationItem.titleView来设置titleview,并且要求达到和屏幕一样宽。
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; label.text = @"月未央"; label.textAlignment = NSTextAlignmentCenter; label.backgroundColor = [UIColor redColor]; self.navigationItem.titleView = label;单纯的设置frame,没有达到预想的效果,效果图如下:
两边总是留出部分“空隙”。查找相关资料,达到的解决方案如下:
继承UIView, 重写其中的setFrame方法。
@implementation GFTitleView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { } return self;}- (void)setFrame:(CGRect)frame { [super setFrame:CGRectMake(0, 0, self.superview.bounds.size.width, self.superview.bounds.size.height)];}使用代码:
titleView = [[GFTitleView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; titleView.backgroundColor = [UIColor redColor]; self.navigationItem.titleView = titleView;
效果图:
1 0
- iOS 设置titleview的宽度为屏幕宽
- ios search bar 设置为navigationitem的titleview时宽度设置无效
- 如何设置Dialog宽度为屏幕宽度
- android 设置dialog 宽度为屏幕宽度
- 设置TableViewCell系统分割线宽度为屏幕宽度
- android 设置AlertDialog样式,宽度为屏幕宽度
- 【IOS学习笔记】为UICollectionView设置自适应屏幕宽度以及点击效果
- ios 设置导航titleView偏移问题
- 【笔记】根据屏幕的宽度动态设置image宽高
- navigationItem的设置和titleView的设置
- 如何根据移动端设备宽度来设置超过屏幕宽度的多余字显示为省略号
- 根据屏幕宽度,设置rem的值
- Dialog显示宽度铺满屏幕宽度的设置
- ios 获取屏幕的属性和宽度
- ios 获取屏幕的属性和宽度
- ios 获取屏幕的属性和宽度
- ios 获取屏幕的属性和宽度
- ios 获取屏幕的属性和宽度
- 最优化javascript自定义对象
- javascript中的创建自定义对象的六种方式详解
- javascript创建自定义对象和prototype
- curl : 操作每一个文件时, 要成对执行 curl_easy_init 和 curl_easy_cleanup
- Sqoop导表在大并发下造成RegionServer的系统cpu过高
- iOS 设置titleview的宽度为屏幕宽
- 再谈JavaScript的用户自定义对象
- javascript基础知识梳理-原始类型
- 桌面邮件飞机源码——VB.NET网络编程简单实例
- 浅谈数据存储之大端法和小端法
- kerberos 认证方式-主机认证
- 第四周作业
- POJ1481_The die is cast(DFS+DFS)
- mysql重装卸载不干净 Error 1045