/*
调整行间距
*/
+ (void)adjustLineSpacingOfLabel:(UILabel *)label to:(CGFloat)lineSpacing
{
NSString *textStr = label.text;
if (textStr.length <= 0) {
return;
} NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textStr];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:lineSpacing];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [textStr length])];
label.attributedText = attributedString;
[label sizeToFit];
} + (CGSize)sizeOfMultiLineLabel:(NSString *)aLabelTextString font:(UIFont *)aLabelFont constrainedToSize:(CGSize)maxSize lineSpacing:(CGFloat)lineSpacing
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) {
//version < 7.0
return [aLabelTextString sizeWithFont:aLabelFont
constrainedToSize:maxSize
lineBreakMode:NSLineBreakByTruncatingTail];
}
else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
//version >= 7.0
//Return the calculated size of the Label
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:lineSpacing];
[paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping]; return [aLabelTextString boundingRectWithSize:maxSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:aLabelFont, NSParagraphStyleAttributeName:paragraphStyle}
context:nil].size;
}
return CGSizeZero;
}

UILabel 调整行间距的更多相关文章

  1. UILabel设定行间距方法

    NSString *textStr = @"iPhone规定:任何应用想访问麦克风,必须被授权麦克风服务.请进入"设置"->"隐私"->& ...

  2. (转)iOS学习——UIlabel设置行间距和字间距

    在iOS开发中经常会用到UIlabel来展示一些文字性的内容,但是默认的文字排版会觉得有些挤,为了更美观也更易于阅读我们可以通过某些方法将UIlabel的行间距和字间距按照需要调节. 比如一个Labe ...

  3. (转载)iOS UILabel自定义行间距时获取高度

    本文介绍一下自定义行间距的UILabel的高度如何获取,需要借助一下开源的UILabel控件:TTTAttributedLabel 附下载地址 https://github.com/TTTAttrib ...

  4. iOS UILabel自定义行间距时获取高度

    本文介绍一下自定义行间距的UILabel的高度如何获取,需要借助一下开源的UILabel控件:TTTAttributedLabel 附下载地址 https://github.com/TTTAttrib ...

  5. UILabel设置行间距和字间距并计算高度-b

    #define UILABEL_LINE_SPACE 6 #define HEIGHT [ [ UIScreen mainScreen ] bounds ].size.height //给UILabe ...

  6. UILabel设置行间距

    UILabel设置行间距: NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWi ...

  7. IOS开发调整UILabel的行间距

    CGFloat heih = 20;   NSString * cLabelString = @"这是测试UILabel行间距的text.这是测试UILabel行间距的text.n 这是测试 ...

  8. 修改UILabel的行间距

    在iOS开发中  有时候为了调整一些UI效果  我们需要调整UILabel之间的行间距: contentLabel.text:label上显示的文字内容; 5:label行间距; contentLab ...

  9. iOS 设置UILabel的行间距并自适应高度

    NSString *contentStr = @"总以为,在最初的地方,有一个最原来的我,就也会有一个最原来的你"; UILabel *tempLabel = [[UILabel ...

随机推荐

  1. jQuery获取浏览器参数

    当我们需要获取浏览器参数是,我们可以使用jQuery进行获取,具体方法如下: 例如获取参数的地址:http://www.test.com?a="111"&b="2 ...

  2. MySQL中的查询子句

    查询语句 字句名称 使用目的 select 确定结果集中应该包含那些列 from 指明所要提取数据的表,以及这些表是如何连接的 where 过滤不需要的数据 group by 用于对具有想用列值的行进 ...

  3. .NET Core Community 首个千星项目诞生:CAP

    项目简介 在我们构建 SOA 或者 微服务系统的过程中,我们通常需要使用事件来对各个服务进行集成,在这过程中简单的使用消息队列并不能保证数据的最终一致性, CAP 采用的是和当前数据库集成的本地消息表 ...

  4. python3全栈开发- 元类metaclass(面试必考题)

    一.知识储备 #exec:三个参数 #参数一:字符串形式的命令 #参数二:全局作用域(字典形式),如果不指定,默认为globals() #参数三:局部作用域(字典形式),如果不指定,默认为locals ...

  5. [LeetCode] Reach a Number 达到一个数字

    You are standing at position 0 on an infinite number line. There is a goal at position target. On ea ...

  6. [LeetCode] Non-negative Integers without Consecutive Ones 非负整数不包括连续的1

    Given a positive integer n, find the number of non-negative integers less than or equal to n, whose ...

  7. Struts2--标签tag

    在Struts2框架中提供了一套标签库,可以与struts2无缝结合. 数据标签a.action.bean.date.debug.i18n.include.param.property.push.se ...

  8. [ZJOI2010]基站选址

    题目描述 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立基站的费用为Ci.如果在距离第i个村庄不超过Si的范 ...

  9. [JSOI2007]文本生成器

    题目描述 JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文本生成器v6版. 该软件可以随机生成一些文章―――总是生成一篇长度 ...

  10. ●BZOJ 1531 [POI2005]Bank notes

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1531 题解: 单调队列优化多重背包DP (弱弱的我今天总算是把这个坑给填了...) 令V[i ...