关于drawInRect: withAttributes: 等新方法的使用
来源:互联网 发布:theone智能钢琴软件 编辑:程序博客网 时间:2024/05/21 11:03
新的方法采用的是 attributes,attributes参数需要的是一个数组
我们常用的有几个:
<code class="hljs ruby has-numbering"> <span class="hljs-constant">NSMutableParagraphStyle</span>* paragraphStyle = [[<span class="hljs-constant">NSParagraphStyle</span> defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = <span class="hljs-constant">NSLineBreakByCharWrapping</span>; <span class="hljs-constant">NSDictionary</span>* dic = @{<span class="hljs-constant">NSFontAttributeName</span><span class="hljs-symbol">:font</span>,<span class="hljs-constant">NSParagraphStyleAttributeName</span><span class="hljs-symbol">:paragraphStyle</span>,<span class="hljs-constant">NSForegroundColorAttributeName</span><span class="hljs-symbol">:</span>[<span class="hljs-constant">UIColor</span> lightGrayColor]};</code><ul style="display: block;" class="pre-numbering"><li>1</li><li>2</li><li>3</li></ul>
通过设置 NSParagraphStyleAttributeName,我们可以设置string的段落风格,比如 lineBreakMode
NSForegroundColorAttributeName 字体颜色
eg:
原先可以这样写:
<code class="hljs mel has-numbering">CGSize <span class="hljs-keyword">size</span> = [<span class="hljs-keyword">text</span> sizeWithFont:font constrainedToSize:CGSizeMake(<span class="hljs-number">300</span>, MAXFLOAT)lineBreakMode:NSLineBreakByCharWrapping];[<span class="hljs-keyword">text</span> drawInRect:CGRectMake(<span class="hljs-number">10</span>,<span class="hljs-number">10</span>,<span class="hljs-number">300</span>, <span class="hljs-keyword">size</span>.height) withFont:font lineBreakMode:NSLineBreakByCharWrapping];</code><ul style="display: block;" class="pre-numbering"><li>1</li><li>2</li></ul>
iOS7 之后需要切换新方法,如下:
<code class="hljs mel has-numbering"> NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; NSDictionary<span class="hljs-variable">*attribute</span> = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle}; CGSize <span class="hljs-keyword">size</span> = [<span class="hljs-keyword">text</span> boundingRectWithSize:CGSizeMake(<span class="hljs-number">300</span>, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].<span class="hljs-keyword">size</span>; [<span class="hljs-keyword">text</span> drawWithRect:CGRectMake(<span class="hljs-number">10</span>, <span class="hljs-number">10</span>,<span class="hljs-number">300</span>, <span class="hljs-keyword">size</span>.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil];</code>
0 0
- 关于drawInRect: withAttributes: 等新方法的使用
- 关于drawInRect: withAttributes: 等新方法的使用
- 关于drawInRect: withAttributes: 等新方法的使用
- 新方法drawInRect:withAttributes的使用
- iOS7下的drawInRect的新方法drawInRect:withAttributes:使用
- NSString的drawInRect: withAttributes:的参数解析
- drawInRect:withAttributes用法
- - (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs;使用
- - (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs;使用
- 关于UVa10048 的新方法
- Ext中关于Function类的一些新方法的使用
- Ext研究(1)——关于Function类的一些新方法的使用
- iOS5中 UIViewController新方法的使用
- iOS5中 UIViewController新方法的使用
- iOS5中 UIViewController新方法的使用
- iOS5中 UIViewController新方法的使用
- iOS5中 UIViewController新方法的使用
- Cocos2d-x-2.2.2的使用新方法
- 昨天,今天,明天 沉溺于!
- 平凡人白日梦,云计算圆我梦!
- js中立即执行函数的介绍
- setsockopt 的用法
- Android Uri带中文乱码问题
- 关于drawInRect: withAttributes: 等新方法的使用
- Mac打不开身份不明的开发者
- 看不懂代码怎么办的百度知道,以及uml的介绍
- iCloud之创建一个数据库通过保存记录
- DB2 查看表数据大小
- DCM使用时输入时钟相关错误
- Java创建对象实例的三种方法
- 不要急躁冒进惹麻烦——年幼无知
- 鲁大师2015如何生成报告|鲁大师检测电脑报告保存方法介绍