第2月第24天 coretext 行高
1.NSMutableAttributedString 行高
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];[paragraphStyle setLineSpacing:LINESPACE];//调整行间距 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];label.attributedText = attributedString;
http://blog.sina.com.cn/s/blog_9256a1210101ku7o.html
2.boundingRectWithSize 行高
#define UILABEL_LINE_SPACE 6 #define HEIGHT [ [ UIScreen mainScreen ] bounds ].size.height //给UILabel设置行间距和字间距 -(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];paraStyle.lineBreakMode = NSLineBreakByCharWrapping;paraStyle.alignment = NSTextAlignmentLeft;paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距paraStyle.hyphenationFactor = 1.0;paraStyle.firstLineHeadIndent = 0.0;paraStyle.paragraphSpacingBefore = 0.0;paraStyle.headIndent = 0;paraStyle.tailIndent = 0;//设置字间距 NSKernAttributeName:@1.5fNSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f };NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];label.attributedText = attributeStr; }//计算UILabel的高度(带有行间距的情况) -(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];paraStyle.lineBreakMode = NSLineBreakByCharWrapping;paraStyle.alignment = NSTextAlignmentLeft;paraStyle.lineSpacing = UILABEL_LINE_SPACE;paraStyle.hyphenationFactor = 1.0;paraStyle.firstLineHeadIndent = 0.0;paraStyle.paragraphSpacingBefore = 0.0;paraStyle.headIndent = 0;paraStyle.tailIndent = 0;NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f };CGSize size = [str boundingRectWithSize:CGSizeMake(width, HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;return size.height; }
http://blog.csdn.net/luco2008/article/details/50977718
3.CTFramesetterSuggestFrameSizeWithConstraints 行高
1)CFMutableAttributedStringRef/NSAttributedString
2)CTParagraphStyleRef/NSMutableParagraphStyle
NSString *text = @"This\nis\nsome\nmulti-line\nsample\ntext." UIFont *uiFont = [UIFont fontWithName:@"Helvetica" size:17.0]; CTFontRef ctFont = CTFontCreateWithName((CFStringRef) uiFont.fontName, uiFont.pointSize, NULL);// When you create an attributed string the default paragraph style has a leading // of 0.0. Create a paragraph style that will set the line adjustment equal to // the leading value of the font. CGFloat leading = uiFont.lineHeight - uiFont.ascender + uiFont.descender; CTParagraphStyleSetting paragraphSettings[1] = { kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof (CGFloat), &leading };CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphSettings, 1); CFRange textRange = CFRangeMake(0, text.length);// Create an empty mutable string big enough to hold our test CFMutableAttributedStringRef string = CFAttributedStringCreateMutable(kCFAllocatorDefault, text.length);// Inject our text into it CFAttributedStringReplaceString(string, CFRangeMake(0, 0), (CFStringRef) text);// Apply our font and line spacing attributes over the span CFAttributedStringSetAttribute(string, textRange, kCTFontAttributeName, ctFont); CFAttributedStringSetAttribute(string, textRange, kCTParagraphStyleAttributeName, paragraphStyle);CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(string); CFRange fitRange;CGSize frameSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, textRange, NULL, bounds, &fitRange);CFRelease(framesetter); CFRelease(string);
http://stackoverflow.com/questions/3374591/ctframesettersuggestframesizewithconstraints-sometimes-returns-incorrect-size
http://blog.sina.com.cn/s/blog_6308b98c0101byh9.html
4.yytext
http://www.cnblogs.com/lujianwenance/p/5716804.html
5.nsattributedstring 转nsstring
6.UILabel和Scrollview结合用,label高度自适应
https://my.oschina.net/langzhouzhou1/blog/648748
7.计算高度
- (CGFloat)boundingRectWithSize:(CGFloat)widthwithAttributedString:(NSMutableAttributedString *)attrt {CGFloat height = 0;NSStringDrawingOptions options =NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;CGRect rect = [attrt boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX)options:optionscontext:nil];height = ceilf(rect.size.height);return height; }- (CGFloat)stringWidthWithSize:(CGSize)size font:(UIFont *)font {CGFloat width;if ([PAUntils isAtLeastIOS_7_0]) {CGRect rect =[self boundingRectWithSize:sizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName : font}context:nil];width = rect.size.width;} else {CGSize strSize = [self sizeWithFont:font constrainedToSize:size];width = strSize.width;}return width; }
转载于:https://www.cnblogs.com/javastart/p/6097513.html
第2月第24天 coretext 行高相关推荐
- CSS行高继承(重点)、覆盖和优先级
层叠性: 离结构近的起作用,就近原则,只会覆盖起冲突的部分 <style>div {color: red; //被后面的覆盖font-size: 12px; // 和后面没有冲突,不会被覆 ...
- 上海房价7月下降24% 创三年最大跌幅
上海房价7月下降24% 创三年最大跌幅 http://www.sina.com.cn 2008年09月05日 01:57 中国证券网-上海证券报 ⊙本报记者 薛明 上海,这个中国房价的最后堡垒 ...
- Web打印连续的表格,自动根据行高分页
拿到这个需求,我已经蛋碎了一地,经过N天的攻克,终于是把它搞定了,只是不知道会不会在某种情况下出现BUG.表示我心虚没有敢做太多的测试.... ---------------------------- ...
- excel 行高 上下留白_拒绝加班,工作中最常用的57个Excel小技巧来了!
今天高顿君分享的 Excel小技巧,全是工作是最常用且简单易操作的,共57个,希望对同学们有所帮助.(适合版本 Excel2007及以上) 一.文件操作 1.为excel文件添加打开密码 文件 - 信 ...
- css文本省略(······)行高错位(bug)- 解决办法
应用css文本省略(······)属性:-webkit-line-clamp: 3; 导致:行高错位.(F12查看发现css属性line-height的值并没变,但为什么浏览器显示文本的实际行距却变小 ...
- easypoi导出一对多,合并单元格,且根据内容自适应行高
easypoi导出一对多,合并单元格,且根据内容自适应行高 EasyPoi一对多导出 一.pom引入依赖 二.导出实体类 excelPoi常用注解说明 @Excel注解 @ExcelCollectio ...
- 基于tabular包的Latex表格尺寸设置方法(列宽和行高)
基于tabular包的Latex表格尺寸设置方法(列宽和行高) tabel语法的小技巧 设置表格的说明文字时,有的场合要求说明文字在表格下方,有的要求说明文字在表格上方,该怎么调整呢? 只需要把\ca ...
- POI Excel行高设置
1.Excel行高单位概述 px是相对长度,表示pixel,像素,是屏幕上显示数据的最基本的点 pt是绝对长度,表示point,磅,是印刷行业常用单位,等于1/72英寸 DPI(或PPI),分辨率,p ...
- html里面行高的原理,CSS行高(line-height)及文本垂直居中原理
在CS多现业讲进行效通近年有务这行定果过近年有S中,line-height 属性设置两段段文本之间的距离,也就是行高,如果我们把一段文本的line-height设置为父容器的高度就可以实现文本垂直居中 ...
最新文章
- 给批量用户设磁盘配额
- 关于VC中的stdafx.h
- linux上传文件到服务器
- .net Kafka.Client多个Consumer Group对Topic消费不能完全覆盖研究总结(一)
- 用C++实现十进制转二进制【个人思想】
- 鲲鹏基础软件开发赛道openLooKeng赛题火热报名中,数十万大奖等您来收割
- matlablib显示图片
- 用yacc编写的算术运算计算器_如何用纯机械实现乘除运算,这是个问题
- Oracle 数据库升级
- C++:STL之vector,deque对比
- invocation, 作者 Medwyn Goodall,女巫医 [搜索 invocation Medwyn Goodall]
- python wget_python wget下载文件
- hdoj 2122 Ice_cream’s world III【最小生成树】
- 信用社pb通用记账_信用社会计记账采用的是()。A、收付实现制B、权责发生制C、借贷记账法D、单式记账法...
- 亿图图示--工业自动化模块--啤酒生产处理流程简图和热水冷凝处理架构
- 管理类联考-英语 : 前导( 四 )
- Java指令-Djava.ext.dirs的陷阱
- 唐诗宋词学习·106~110节
- 使用离散元法DEM进行转鼓内颗粒动力学研究
- NCC通过前台页面查找后台类