第9月第9天 CTFramesetterCreateWithAttributedString
1.
- 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);
- // direction
- CTWritingDirection direction = kCTWritingDirectionLeftToRight;
- // leading
- CGFloat firstLineIndent = 0.0;
- CGFloat headIndent = 0.0;
- CGFloat tailIndent = 0.0;
- CGFloat lineHeightMultiple = 1.0;
- CGFloat maxLineHeight = ;
- CGFloat minLineHeight = ;
- CGFloat paragraphSpacing = 0.0;
- CGFloat paragraphSpacingBefore = 0.0;
- CTTextAlignment textAlignment = kCTTextAlignmentLeft;//(CTTextAlignment)_textAlignment;
- CTLineBreakMode lineBreakMode = kCTLineBreakByWordWrapping;//(CTLineBreakMode)_lineBreakMode;
- CGFloat lineSpacing = ;//_lineSpacing;
- CTParagraphStyleSetting theSettings[] =
- {
- { kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &textAlignment },
- { kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBreakMode },
- { kCTParagraphStyleSpecifierBaseWritingDirection, sizeof(CTWritingDirection), &direction },
- { kCTParagraphStyleSpecifierMinimumLineSpacing, sizeof(CGFloat), &lineSpacing }, // leading
- { kCTParagraphStyleSpecifierMaximumLineSpacing, sizeof(CGFloat), &lineSpacing }, // leading
- { kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(CGFloat), &firstLineIndent },
- { kCTParagraphStyleSpecifierHeadIndent, sizeof(CGFloat), &headIndent },
- { kCTParagraphStyleSpecifierTailIndent, sizeof(CGFloat), &tailIndent },
- { kCTParagraphStyleSpecifierLineHeightMultiple, sizeof(CGFloat), &lineHeightMultiple },
- { kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &maxLineHeight },
- { kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &minLineHeight },
- { kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), ¶graphSpacing },
- { kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), ¶graphSpacingBefore }
- };
- CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, sizeof(theSettings) / sizeof(CTParagraphStyleSetting));
- CFRange textRange = CFRangeMake(, 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(, ), (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, self.view.bounds.size, &fitRange);
CFRelease(paragraphStyle);
CFRelease(ctFont);
- CFRelease(framesetter);
- CFRelease(string);
https://github.com/honcheng/RTLabel
https://stackoverflow.com/questions/3374591/ctframesettersuggestframesizewithconstraints-sometimes-returns-incorrect-size
第9月第9天 CTFramesetterCreateWithAttributedString的更多相关文章
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- js获取给定月份的N个月后的日期
1.在讲js获取给定月份的N个月后的日期之前,小颖先给大家讲下getFullYear().getYear()的区别. ①getYear() var d = new Date() console.log ...
- 张小龙宣布微信小程序1月9日发布,并回答了大家最关心的8个问题
2016 年 12 月 28 日,张小龙在微信公开课 PRO 版的会场上,宣布了微信小程序的正式发布时间. 微信小程序将于 2017 年 1 月 9 号正式上线. 同时他解释称,小程序就像PC时代的网 ...
- 【代码笔记】iOS-获得当前的月的天数
一,代码. #import "ViewController.h" @interface ViewController () @end @implementation ViewCon ...
- 怎样两个月完成Udacity Data Analyst Nanodegree
在迷恋数据科学很久后,我决定要在MOOC网站上拿到一份Data Science的证书.美国三个MOOC网站,Udacity上的课程已经被分成了数个nanodegree,每个nanodegree都是目前 ...
- 我想立刻辞职,然后闭关学习编程语言,我给自己3个月时间学习C语言!这样行的通吗
文章背景,回答提问:我想立刻辞职,然后闭关学习编程语言,我给自己3个月时间学习C语言!这样行的通吗? 我的建议是这样:1. 不要辞职.首先说,你对整个开发没有一个简单的了解,或一个系统的入门学习.换句 ...
- 【月入41万】Mono For Android中使用百度地图SDK
借助于Mono For Android技术,.Net开发者也可以使用自己熟悉的C#语言以及.Net来开发Android应用.由于Mono For Android把Android SDK中绝大部分类库都 ...
- CS Coder学习asp.net5个月的最大感悟:从http的角度重新认识asp.net(二)——我理解的ajax(二)
啊哈,时隔两个月,才开始写上一篇文章的后续,实在是惭愧.主要是年尾公司又来活了,忙得团团转,而且这段时间在自学mvc.我在上文中,提到过我对mvc框架的初步印象是:相比webform,算是回归了bs本 ...
- C#得到某月最后一天晚上23:59:59和某月第一天00:00:00
项目需求: 某学校订单截止操作时间的上一个月最后一天晚上23:59:59 为止所有支付的订单统计: 代码: /// <summary> /// 通过学校和截止时间得到订单 /// < ...
随机推荐
- HyperLedger Fabric 学习思路分享
HyperLedger Fabric 学习思路分享 HyperLedger Fabric最初是由Digital Asset和IBM公司贡献的.由Linux基金会主办的一个超级账本项目,它是一个目前非常 ...
- 认识 Iconfont 以及什么是 .eot、.woff、.ttf、.svg
一.Iconfont 1. 概述 在前端作业中,二十年前只有页面中铺满文字就算上线产品,现如今,不加点俏皮的“图标”会让页面显得很 Low 很 Low. 图标 在写这篇文章之前,我一直以为上图中的 ...
- Notes of Daily Scrum Meeting(11.12)
今天我们召开了Beta阶段MOOC项目开发的第一次Scrum Meeting,在会上就alpha阶段进行了总结,然后我们确定了 接下来的Beta阶段的项目分工,并且就每天的进度汇报做了一个约定,就是每 ...
- 调研android开发环境的发展演变
这是第一次接触android开发,特意上网搜索视频进行了自身知识补充,觉得说视频做得很不错,从android的发展历程以及一些基本常识都讲得很详细,也很有趣,也所以拿出来同大家一起分享学习,网址是:h ...
- 我是一个程序猿 ——《不是书评 :<我是一只IT小小鸟>》有感
读了刘未鹏先生的文章<不是书评 :<我是一只IT小小鸟>>,产生了诸多共鸣,更明白了不少道理. 首先是一个很平常的现象,进度条效应,在操作移动终端上的软件时,如果没有进度条,人 ...
- 如何向妻子解释OOD
前言 此文译自CodeProject上<How I explained OOD to my wife>一文,该文章在Top Articles上排名第3,读了之后觉得非常好,就翻译出来, ...
- git 生成秘钥
Permission denied (publickey). fatal: The remote end hung up unexpectedly 应该是ssh key过期了吧 试着重新创建ssh k ...
- du 显示 前面以及或者两级的目录大小的方法
mark 一下 du -h --max-depth=
- windows日志查看-非法关机判断方法
日志文件,它记录着Windows系统及其各种服务运行的每个细节,对增强Windows的稳定和安全性,起着非常重要的作用.但许多用户不注意对它保护,一些“不速之客”很轻易就将日志文件清空,给系统带来严重 ...
- blog 社会化评论插件 多说for china, disqus for global range
1.disqus https://disqus.com/ https://publishers.disqus.com/engage https://disqus.com/admin/create/ h ...