关于drawInRect: withAttributes: 等新方法的使用
来源:互联网 发布:网易邮箱客户端mac版 编辑:程序博客网 时间:2024/05/18 02:26
新的方法采用的是 attributes,attributes参数需要的是一个数组
我们常用的有几个:
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; NSDictionary* dic = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:[UIColor lightGrayColor]};
通过设置 NSParagraphStyleAttributeName,我们可以设置string的段落风格,比如 lineBreakMode
NSForegroundColorAttributeName 字体颜色
eg:
原先可以这样写:
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(300, MAXFLOAT)lineBreakMode:NSLineBreakByCharWrapping];[text drawInRect:CGRectMake(10,10,300, size.height) withFont:font lineBreakMode:NSLineBreakByCharWrapping];
iOS7 之后需要切换新方法,如下:
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; NSDictionary*attribute = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle}; CGSize size = [text boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size; [text drawWithRect:CGRectMake(10, 10,300, size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil];
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的使用新方法
- JAVA实现EXCEL公式专题(四)——字符串函数
- 《集体智慧编程》学习笔记001
- 为Raspberry Pi 2编译内核模块
- NSIS 自定义界面布局简介 (学习四)
- iOS开发 -- UITextField
- 关于drawInRect: withAttributes: 等新方法的使用
- HDU Prime Ring Problem (DFS+素数打表)
- Kurento应用开发指南(以Kurento 5.0为模板) 之四:示例教程 一对一视频呼叫
- 应用程序的编译和打包
- Spring中常用注解的介绍
- android的点九图制作
- OAF学习笔记-4-lov的制作
- Android Animations动画使用详解
- Lua逻辑and和or的设计和三目运算符