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 ...
随机推荐
- JAVA SE回顾及思考(1)——面向对象的特点
学习Java已经三年了,现在开始做Android开发,虽说还在用Java语言但本人现在才真真的意识到无论学什么基础才是最重要的,可能一些刚接触Java或者Android的朋友现在还体会不到基础的重要性 ...
- java 保存和读取本地json文件
保存数据到本地文件 private void saveDataToFile(String fileName,String data) { BufferedWriter writer = null; F ...
- 用java写的后台方法可以提供给C#调用吗?(转)
最近和公司搞C#的同事联合搞了一个项目,我把我这边的数据加密之后传给C#,然后C#在对接收到的数据解密.可是问题来了,我这边用JAVA加密的数据C#的同事怎么也解密不出来,于是我就想到了可不可以将JA ...
- WPF 控制程序只能启动一次
原文:WPF 控制程序只能启动一次 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jsyhello/article/details/7411898 ...
- C++第11周(春)项目4 - 类族的设计
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目4 - 类族的设计]按下面的提示,由基类 ...
- #748 – 获得按下时对应位置点的大小(Getting the Size of a Contact Point during Raw Touch)
原文:#748 – 获得按下时对应位置点的大小(Getting the Size of a Contact Point during Raw Touch) 原文地址:https://wpf.2000t ...
- 从Header中获得信息
/// <summary> /// 获得header信息 /// </summary> /// <param name="response">& ...
- debian安装node.js
1,先下载nodejs: # wget http://nodejs.org/dist/v0.8.7/node-v0.8.7.tar.gz 2,解压文件 # tar xvf node-v0.8.7.ta ...
- WPF 视图导航
<Window x:Class="ViewExam.MainWindow" xmlns="http://schemas.microsoft.com/w ...
- 利用最小二乘法拟合任意次函数曲线(C#)
原文:利用最小二乘法拟合任意次函数曲线(C#) ///<summary> ///用最小二乘法拟合二元多次曲线 ///</summary> ///< ...