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]; |