#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范例实现代码如下的更多相关文章

  1. python集合使用范例的代码

    在代码过程中中,将代码过程中比较好的代码段珍藏起来,如下的代码是关于python集合使用范例的代码,希望能对大伙有用. # sets are unordered collections of uniq ...

  2. python 类继承演示范例的代码

    把做工程过程重要的代码片段备份一次,下面的资料是关于python 类继承演示范例的代码. # a simple example of a class inheritance # tested with ...

  3. linux c ---raise 使用范例的代码

    把做工程过程中比较好的代码片段收藏起来,下面代码内容是关于linux c ---raise 使用范例的代码,希望对各位有所用途. #include <sys/types.h> #inclu ...

  4. 对《神奇的C语言》文中例子 5 代码的分析讨论

    在春节前,我曾经参与在<神奇的C语言>一文中的例子(5)的讨论,但限于评论内容的有限,现在本文再次对这个问题单独讨论.(此问题原貌,详见<神奇的C语言>,这里我将原文中的代码稍 ...

  5. php使用正则过滤js脚本代码实例

    匹配的规则不能用 "/<script.*<\/script>/i",因为它不能匹配到换行符,那么多行js就匹配不掉了. 要用 "/<script[ ...

  6. 让UILabel的文字顶部对齐

    参考资料 http://stackoverflow.com/questions/1054558/how-do-i-vertically-align-text-within-a-uilabel 方法一 ...

  7. 30个php操作redis常用方法代码例子

    From: http://www.jb51.net/article/51884.htm 这篇文章主要介绍了30个php操作redis常用方法代码例子,本文其实不止30个方法,可以操作string类型. ...

  8. [ios]纯代码实现UITableViewCell的自定义扩展

    (转)参考:http://blog.sina.com.cn/s/blog_65cbfb2b0101cd60.html 第一种, 简单的增加UITableViewCell一些小功能 例如在cell上面添 ...

  9. 控制UIlabel 垂直方向对齐方式的 方法

    最正统的方法,利用objective-c的category特性,修改UILabel的绘制代码.示例代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

随机推荐

  1. Android Studio打包apk,aar,jar包

    转载请标明出处:一片枫叶的专栏 文本我们将讲解android studio打包apk,aar,jar包的相关知识.apk包就是android系统的安装包,这里没什么好说的,aar包是android中独 ...

  2. android 如何创建配置文件和读配置文件

    因为一些配置信息,多处用到的.且以后可能变更的,我想写个.prorperties配置文件给管理起来.在studio中新建一个Assets文件-->新建一个file文件类型为properties文 ...

  3. 北大SQL数据库视频课程笔记

    Jim Gray - Transaction processing: concepts and techniqueshttp://research.microsoft.com/~gray/ 事务概念 ...

  4. 使用Adorner显示WPF控件的边界点

    原文:使用Adorner显示WPF控件的边界点 当我们拖动WPF控件时,我们为了更清楚地需要显示控件,一般我们会在WPF控件所围成的矩形区域的四个边界点上作一个特殊的记号(比如圆点).如下图: 在Wi ...

  5. 构建自己的PHP框架(视图装载)

    完整项目地址:https://github.com/Evai/Aier 视图装载类要做的工作其实很简单: 1. 根据视图名称找到视图文件,支持文件夹 2. 更加方便,更加优雅地把变量的值传递进视图 本 ...

  6. python解决urllib2乱码问题

    示例: #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib import urllib2 def main(): url = &qu ...

  7. 潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据

    原文:潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据 目前自己对treeview的感慨很多 今天先讲 面对这种 表结构的数据 的其中 ...

  8. oracle_set运营商

     oracle_set运营商 ①UNION/UNION ALL UNION 运算符返回的结果集,并设置两个查询.对于这两组重复部分的.重复数据删除 例: select id,name from t ...

  9. WPF - 本质:数据和行为

    原文:WPF - 本质:数据和行为 如果自己来做一个UI框架,我们会首先关注哪些方面?我想UI框架主要处理的一定包括两个主要层次的内容,一个是数据展现,另一个就是数据操作,所以UI框架必须能够接收各种 ...

  10. Bind Enum to Combobox.SelectedIndex

    原文:Bind Enum to Combobox.SelectedIndex Do you mean that you want to bind a variable (not a property) ...