#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. Swift下CoreData的使用

    我之前的随笔中有写过一些iOS持久化存储的方法,包含了sqlite.解归档.沙盒存放等等.这些方式中,能够大规模存储,并保持性能的只有使用sqlite了.而这里将记录下Cocoa自身继承的数据库的存储 ...

  2. 使用XCA(X Certificate and key management)可视化项目经理SSL 凭证(4)--凭借自身的凭证管理中心的定义(Certificate Authority)签名证书申请

    随着XCA(X Certificate and key management)可视化项目经理SSL 证书系列文章(2)和(3)中.我们学习了怎样用XCA(X Certificate and key m ...

  3. ADO.net之2-成功连接到数据库---ShinePans

    配置数据库: 连接字符串: server=潘尚\\SQLEXPRESS;database=db_test;Trusted_Connection=true 连接代码: using System; usi ...

  4. 使用 matlab 数据集的生成(generate datasets)

    一般手工生成的数据集(artificial datasets),通常用于实验部分最开始的演示和示意,用于对结果的一种精确计算和量化分析. 1. Swiss/Helix/Twinpeaks/Broken ...

  5. WPF 呼吸灯特效

    原文:WPF 呼吸灯特效 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u014117094/article/details/46738621 pa ...

  6. OpenGL(十四) 模板测试

    启用模板测试时,OpenGL会在内存中开辟一块空间作为模板缓冲区,里边保存了每个像素的"模板值",模板测试的过程就是把每一个像素的模板值与一个设定的模板参考值进行比较,符合设定条件 ...

  7. [WPF疑难]ErrorTemplate显示与隐藏问题

    原文:[WPF疑难]ErrorTemplate显示与隐藏问题 [WPF疑难]ErrorTemplate显示与隐藏问题                                         周 ...

  8. 【转载】如何使用docker部署c/c++程序

    原文地址:https://blog.csdn.net/len_yue_mo_fu/article/details/80189035 Docker介绍 Docker是一个开源的容器引擎,它有助于更快地交 ...

  9. 生成EF后修改最大长度限制等

      右键属性    

  10. KVM虚拟化知识的一些笔记

    一.KVM介绍 KVM:运行在内核空间,提供CPU 和内存的虚级化,以及客户机的 I/O 拦截.Guest 的 I/O 被 KVM 拦截后,交给 QEMU 处理. QEMU:修改过的为 KVM 虚机使 ...