A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© xiaochongzi 中级黑马   /  2015-12-1 09:05  /  2794 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

10黑马币
NSMutableAttributedString  需求NSMutableAttributedString的初级学习和进阶

3 个回复

倒序浏览
http://snowyshell.blog.163.com/blog/static/2209140342014475383375/

http://blog.csdn.net/zhangao0086/article/details/7616385

网上找的两篇博客,希望对你有用
回复 使用道具 举报
1 // initWithString:  
2 NSAttributedString *attributedString_str = [[NSAttributedString alloc] initWithString:@"attributedString"];  
3 NSLog(@"%@", attributedString_str);  
4 // textView.attributedText = attributedString_str;  
5   
6   
7 // initWithAttributedString:  
8 NSAttributedString *attributedString_atts = [[NSAttributedString alloc] initWithAttributedString:attributedString_str];  
9 NSLog(@"%@", attributedString_atts);  
10 // textView.attributedText = attributedString_atts;  
11   
12   
13 // initWithString:attributes:  
14 UIColor *backgroundColor = [UIColor blackColor];  
15 NSNumber *baseLineOffset = [NSNumber numberWithFloat:20.0];  
16 UIColor *foregroundColor = [UIColor whiteColor];  
17 NSNumber *kern = [NSNumber numberWithFloat:5.0];  
18 NSNumber *ligature = [NSNumber numberWithFloat:3.0];  
19 NSURL *linkURL = [NSURL URLWithString:@"http://www.baidu.com"];  
20 NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];  
21 NSDictionary *attrsDic = @{NSForegroundColorAttributeName: foregroundColor,  
22                            NSBackgroundColorAttributeName: backgroundColor,  
23                            NSBaselineOffsetAttributeName: baseLineOffset,  
24                            NSKernAttributeName: kern,  
25                            NSLigatureAttributeName: ligature,  
26                            NSLinkAttributeName: linkURL,  
27                            NSUnderlineStyleAttributeName: underline  
28                            };  
29 NSAttributedString *attributedString_str_atts = [[NSAttributedString alloc] initWithString:@"http://www.baidu.com" attributes:attrsDic];  
30 NSLog(@"%@", attributedString_str_atts);  
31 // textView.attributedText = attributedString_str_atts;  
32   
33   
34 // initWithFileURL:options:documentAttributes:error:  
35 NSURL *fileURL = nil;  
36 fileURL = [[NSBundle mainBundle] URLForResource:@"Dynamic Coloring" withExtension:@"rtf"];  
37 NSAttributedString *attributedString_fileURL = [[NSAttributedString alloc] initWithFileURL:fileURL options:@{} documentAttributes:nil error:nil];  
38 NSLog(@"%@", attributedString_fileURL);  
39 // textView.attributedText = attributedString_fileURL;  
40   
41   
42 // initWithData:options:documentAttributes:error:  
43 fileURL = nil;  
44 fileURL = [[NSBundle mainBundle] URLForResource:@"View Layout" withExtension:@"rtf"];  
45 NSData *data = [[NSData alloc] initWithContentsOfURL:fileURL];  
46 NSAttributedString *attributedString_data = [[NSAttributedString alloc] initWithData:data options:@{} documentAttributes:nil error:nil];  
47 NSLog(@"%@", attributedString_data);  
48 // textView.attributedText = attributedString_data;  
49   
50   
51 // initWithAttributedString:  
52 NSMutableAttributedString *mutableAttributedString_attrs = [[NSMutableAttributedString alloc] initWithAttributedString:attributedString_fileURL];
回复 使用道具 举报
大兄弟,这个行不行?求赐教
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马