UILabel范例实现代码如下
#import "TWO_ViewController.h" #define SCREEN_Width [[UIScreen mainScreen] bounds].size.width @interface TWO_ViewController () @end @implementation TWO_ViewController - (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor blackColor]]; UIView *headerView = [[UIView alloc] init];
UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(, , SCREEN_Width - , )];
image1.backgroundColor = [UIColor redColor]; UILabel *ddlabel = [[UILabel alloc] init];
[ddlabel setText:@"根据文字 高度进行适应根据文字高度 进行自适应根据文适应 根据文字高度进行自适应根据文自适应根据文字高度进行自适应根据文字高度进行自适应根据文字高度进行自适应根据文字高度进行自适应"];
ddlabel.numberOfLines = ;
ddlabel.font = [UIFont systemFontOfSize:]; CGRect rect = [ddlabel.text boundingRectWithSize:CGSizeMake(self.view.frame.size.width - , MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: ddlabel.font} context:nil]; ddlabel.frame = CGRectMake(, CGRectGetMaxY(image1.frame),SCREEN_Width - ,rect.size.height); [self setLineSpacing: label:ddlabel]; //[ddlabel sizeToFit]; UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(, CGRectGetMaxY(ddlabel.frame), SCREEN_Width - , )];
image2.backgroundColor = [UIColor blueColor]; headerView.frame = CGRectMake(, , SCREEN_Width, CGRectGetMaxY(image2.frame)+);
NSLog(@"test height = %f", ddlabel.frame.size.height);
headerView.backgroundColor = [UIColor whiteColor];
[headerView addSubview:image1];
[headerView addSubview:ddlabel];
[headerView addSubview:image2];
[self.view addSubview:headerView];
// Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)setLineSpacing:(CGFloat)spacing label:(UILabel *)label
{
if(!label.text.length) return;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:spacing];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(, [label.text length])];
[label setAttributedText:attributedString];
label.lineBreakMode = NSLineBreakByTruncatingTail;
[label sizeToFit]; //[attributeString setAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFont systemFontOfSize:Near_Final_Font_T9]} range:NSMakeRange(i, 1)];
} @end
UILabel范例实现代码如下的更多相关文章
- python集合使用范例的代码
在代码过程中中,将代码过程中比较好的代码段珍藏起来,如下的代码是关于python集合使用范例的代码,希望能对大伙有用. # sets are unordered collections of uniq ...
- python 类继承演示范例的代码
把做工程过程重要的代码片段备份一次,下面的资料是关于python 类继承演示范例的代码. # a simple example of a class inheritance # tested with ...
- linux c ---raise 使用范例的代码
把做工程过程中比较好的代码片段收藏起来,下面代码内容是关于linux c ---raise 使用范例的代码,希望对各位有所用途. #include <sys/types.h> #inclu ...
- 对《神奇的C语言》文中例子 5 代码的分析讨论
在春节前,我曾经参与在<神奇的C语言>一文中的例子(5)的讨论,但限于评论内容的有限,现在本文再次对这个问题单独讨论.(此问题原貌,详见<神奇的C语言>,这里我将原文中的代码稍 ...
- php使用正则过滤js脚本代码实例
匹配的规则不能用 "/<script.*<\/script>/i",因为它不能匹配到换行符,那么多行js就匹配不掉了. 要用 "/<script[ ...
- 让UILabel的文字顶部对齐
参考资料 http://stackoverflow.com/questions/1054558/how-do-i-vertically-align-text-within-a-uilabel 方法一 ...
- 30个php操作redis常用方法代码例子
From: http://www.jb51.net/article/51884.htm 这篇文章主要介绍了30个php操作redis常用方法代码例子,本文其实不止30个方法,可以操作string类型. ...
- [ios]纯代码实现UITableViewCell的自定义扩展
(转)参考:http://blog.sina.com.cn/s/blog_65cbfb2b0101cd60.html 第一种, 简单的增加UITableViewCell一些小功能 例如在cell上面添 ...
- 控制UIlabel 垂直方向对齐方式的 方法
最正统的方法,利用objective-c的category特性,修改UILabel的绘制代码.示例代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
随机推荐
- 添加cordova-plugin-file-opener2后,打包出错
原文:添加cordova-plugin-file-opener2后,打包出错 报错如下: * What went wrong: Execution failed for task ':app:proc ...
- node与webpack的process.env.NODE_ENV
先看两篇文章 1.前端工程项目的NODE_ENV 2. Node 环境变量 process.env.NODE_ENV 之webpack应用 3.process.env.NODE_ENV 下面全部是在w ...
- WCF客户端C#代码 配置config文件
不多说了,直接上代码吧.... 服务端Web.config文件中bindings配置 <bindings> <wsHttpBinding> <binding name=& ...
- 世界卫生组织(WHO)发出最新警告:埃博拉疫情应急响应
10月14r日.世界卫生组织(WHO)发出警告:在未来两个月内,西非国家将面对"could face up to 10 thousand new Ebola cases a week wit ...
- How to provide highlighting with Spring data elasticsearch
How to provide highlighting with Spring data elasticsearch @Test public void shouldReturnHighlighted ...
- HDU 1598 find the most comfortable road (罗列+Kruskal) 并检查集合
Problem Description XX星有很多城市,城市之间通过一种奇怪的快速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流.每条SARS都对行驶 ...
- 分析MySQL各项指标
MySQL各项指标(因为这不是大多数搜索引擎的区别故意) INDEX(总指数):主要指标,不管是什么限制 ALTER TABLE `table_name` ADD INDEX index_name ( ...
- python 教程 第十三章、 特殊的方法
第十三章. 特殊的方法 1) 特殊的方法 __init__(self,...) 这个方法在新建对象恰好要被返回使用之前被调用. __del__(self) 恰好在对象要被删除之前调用. __st ...
- It's about trust
所有问题, 最后,它归结为:信任. 你能相信别人? 我不是Low esteem.相反,我有信心.问题是.我有一个别人缺乏信任的. Daria家长们说,伪君子:我们必须相信你. Daria马上问:然后, ...
- 【Struts2学习笔记(3)】至Action注入属性值
(1)有属性注入? 当一些属性不适合固定写入时适合使用这样的方法,对于一些使用特频繁的类或者方法,非常多类都会用到,那么使用属性注入会节省很多其它的力气.并且在设计的时候就能够提早的把该属性给定义出来 ...