UILabel实现自适应宽高需要注意的地方(二)
- UILabel “上期” 距离屏幕最左边 有35px
- UILabel “下期” 距离屏幕最右边 有35px
- 进行中文字在UIlabel 中间

- “上期"距离左边35,设置“上期”的X坐标为35即可。设置“上期”的Y坐标为整个头部(红色View)的中心位置即可,通过红色View的Frame高度 来得到他的中心轴的坐标。
- “下期”距离右边35,这个就无法通过直接设置35的距离来保持和右边边界距离刚好为35,要知道“下期”这个UIlabel的宽度,设置“下期”的X坐标为UIlabel“下期”的宽度 + 35px 即可。UILabel宽度如何获取?
{
if (nil == self.text || [@“" isEqualToString:self.text]) {
return CGSizeZero;
}
CGRect contentFrame = [self.textboundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:self.font}
context:nil];
return CGSizeMake(ceil(contentFrame.size.width + 0.5), ceil(contentFrame.size.height + 0.5));
}
- (CGSize)contentSizeForWidthUsesDeviceMetrics:(CGFloat)width
{
CGRect contentFrame = [self.textboundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesDeviceMetrics
attributes:@{NSFontAttributeName:self.font}
context:nil];
return CGSizeMake(ceil(contentFrame.size.width + 0.5), ceil(contentFrame.size.height + 0.5));
}
- (CGSize)contentSize
{
CGFloat screenWidth = [[UIScreenmainScreen] bounds].size.width;
return [self contentSizeForWidth:screenWidth];
}
- (BOOL)isTruncated
{
CGSize size = [self.textboundingRectWithSize:CGSizeMake(self.bounds.size.width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:self.font}
context:nil].size;
return (size.height > self.frame.size.height);
}

_topView.backgroundColor = NF_Color_C19;
_topViewBigLabel = [[UILabelalloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
_topViewBigLabel.font = [UIFont systemFontOfSize:Near_Final_Font_T4];
_topViewBigLabel.textColor = NF_Color_C1;
_topViewBigLabel.text = @"进行中";
[_topViewBigLabelsizeToFit];
_topViewBigLabel.center = CGPointMake(_topView.bounds.size.width/2,_topView.bounds.size.height/2);
[self.view addSubview:_topView];
[self.view addSubview:_topViewBigLabel];
_topViewleftLabel = [[UILabelalloc] init];
_topViewleftLabel.font = [UIFont systemFontOfSize:Near_Final_Font_T9];
_topViewleftLabel.textColor = NF_Color_C1;
_topViewleftLabel.text = @"上期";
_topViewleftLabel.frame = CGRectMake(35, 0, 0, 0);
[_topViewleftLabelsizeToFit];
_topViewleftLabel.centerY = _topView.bounds.size.height/2;
[_topView addSubview:_topViewleftLabel];
_topViewrightLabel = [[UILabelalloc] init];
_topViewrightLabel.font = [UIFont systemFontOfSize:Near_Final_Font_T9];
_topViewrightLabel.textColor = NF_Color_C1;
_topViewrightLabel.text = @"下期";
_topViewrightLabel.frame = CGRectMake(SCREEN_WIDTH-_topViewrightLabel.contentSize.width-35, 0, 0, 0);
[_topViewrightLabelsizeToFit];
_topViewrightLabel.centerY = _topView.bounds.size.height/2;
[_topView addSubview:_topViewrightLabel];
UILabel实现自适应宽高需要注意的地方(二)的更多相关文章
- UILabel实现自适应宽高需要注意的地方(三)
一.需求图如下所示 UILabel 的高度自适应 UILabel中的段落间距可设置 图片效果如下: 调整段落适应长宽高方式: 需求: 保证"游戏玩法 ...
- UILabel实现自适应宽高需要注意的地方
需求如下: 需要显示2行文字,宽度为 SCREEN_Width - 40 高度为两行文本的自适应高度 需要在此UILabel 下面添加imageView , 因此UIlabel 的高度需要准确,不 ...
- 小程 序swiper自适应宽高
https://blog.csdn.net/qq_31604363/article/details/73715944 小程 序swiper自适应宽高 小程 序swiper自适应宽高
- OpenGL ES学习笔记(二)——平滑着色、自适应宽高及三维图像生成
首先申明下,本文为笔者学习<OpenGL ES应用开发实践指南(Android卷)>的笔记,涉及的代码均出自原书,如有需要,请到原书指定源码地址下载. <Android学习笔记--O ...
- iOS - web自适应宽高(预设置的大小)
//web自适应宽高 -(void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"wessd"); [ webView s ...
- iview Carousel 轮播图自适应宽高;iview 轮播图 图片重叠问题;iview tabs 高度互相影响问题;vue this问题;
最终效果图: 一.轮播图中图片自适应宽高: <Carousel loop v-bind:height="imgHeight+'px'" v-model="caro ...
- UILabel 自适应宽高
#import <UIKit/UIKit.h> @interface UILabel (UILabel_LabelHeighAndWidth) + (CGFloat)getHeightBy ...
- js和php计算图片自适应宽高算法实现
js Code: <script> $width = $(imgobj).width(); //图原始宽 $newheight = $(imgobj).height(); //图原始高 $ ...
- css background-image 自适应宽高——转载
就是这么简单的一句话,设置背景图,并让它100%的适应导航栏宽高,并设置不重复,大小100%就OK了 .zjhn-nav li.active a{ background-image:url(../im ...
随机推荐
- C#MVC中创建多模块web应用程序
当一个应用程序有越来越多的子模块后,应用程序将变得越来越大,复杂度也越来越高,应用程序也越来越难维护.如果把每个子模块,独立分成不同的web应用程序,则这个项目将易于维护.关于这个的好处,我也描述得不 ...
- Residential Gateway System for Home Network Service
Disclosed herein is a Residential Gateway (RG) system for home network service. The RG system receiv ...
- 漫步Unity3D(一)
前言 采用Unity它已经将近半年的时间,虽然项目仅仅是一个半成品.但Unity熟几乎相同的游戏.在这里,在使用过程中遇到的问题,再梳.不涉及过于详细的功能和代码.但是,假设他们将参与开发一个在线知识 ...
- android:layout_gravity和android:gravity属性的差别
gravity的中文意思就是"重心",就是表示view横向和纵向的停靠位置 android:gravity:是对view控件本身来说的,是用来设置view本身的文本应该显示在vie ...
- element-ui 自定义表单验证 , 但是不出现小红心了
基本上按照文档上提供的方式做就没啥大问题 , 我遇到的问题是 , 自定义以后不显示小红星了 <el-form :model="ruleForm2" status-icon : ...
- redis 学习笔记——持久化
redis持久化 snapshot数据快照(rdb) 这是一种定时将redis内存中的数据写入磁盘文件的一种方案,这样保留这一时刻redis中的数据镜像,用于意外回滚.redis的snapshot的格 ...
- Java--分布式系统高并发解决方案
对于我们开发的网站,如果网站的访问量非常大的话,那么我们就需要考虑相关的并发访问问题了.而并发问题是绝大部分的程序员头疼的问题, 但话又说回来了,既然逃避不掉,那我们就坦然面对吧~今天就让我们一起来研 ...
- 简述WPF中的图像像素格式(PixelFormats)
原文:简述WPF中的图像像素格式(PixelFormats) --------------------------------------------------------------------- ...
- Java Class SecurityManager
# 前言 简单了解 SecurityManager.具体查阅 API. # What 它是 Java 沙盒模型控制安全的重要一个环节.它是 Java 的一个类.下面一段话源于SecurityManag ...
- hexo-theme-next
Hexo Next github主页:https://github.com/iissnan/hexo-theme-next 官网地址:http://theme-next.iissnan.com/ 一篇 ...