首页 > 其他 > 详细

第5课源代码

时间:2015-11-28 01:05:04      阅读:328      评论:0      收藏:0      [点我收藏+]
 1 //
 2 //  ViewController.m
 3 //  Attributor
 4 //
 5 //  Created by qiuda bin on 15/11/26.
 6 //  Copyright © 2015年 qiuda bin. All rights reserved.
 7 //
 8 
 9 #import "ViewController.h"
10 
11 @interface ViewController ()
12 
13 @property (weak, nonatomic) IBOutlet UITextView *body;
14 @property (weak, nonatomic) IBOutlet UILabel *headline;
15 @property (weak, nonatomic) IBOutlet UIButton *outlineButton;
16 
17 @end
18 
19 @implementation ViewController
20 
21 - (void)viewDidLoad {
22     [super viewDidLoad];
23     // Do any additional setup after loading the view, typically from a nib.
24     NSMutableAttributedString *title =
25     [[NSMutableAttributedString alloc] initWithString:self.outlineButton.currentTitle];
26     
27     [title setAttributes:@{NSStrokeWidthAttributeName: @3,
28                            NSStrokeColorAttributeName: self.outlineButton.tintColor}
29                    range:NSMakeRange(0, [title length])];
30     [self.outlineButton setAttributedTitle:title forState:UIControlStateNormal];
31 }
32 
33 - (void)viewWillAppear:(BOOL)animated
34 {
35     [super viewWillDisappear:animated];
36     [self usePerferredFonts];
37     [[NSNotificationCenter defaultCenter] addObserver:self
38                                              selector:@selector(perferredFontsChanged:)
39                                                  name:UIContentSizeCategoryDidChangeNotification
40                                                object:nil];
41 }
42 
43 - (void)perferredFontsChanged:(NSNotification *)notification
44 {
45     [self usePerferredFonts];
46 }
47 
48 - (void) usePerferredFonts
49 {
50     self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
51     self.headline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
52 }
53 
54 - (void)viewWillDisappear:(BOOL)animated
55 {
56     [super viewWillDisappear:animated];
57     [[NSNotificationCenter defaultCenter] removeObserver:self
58                                                     name:UIContentSizeCategoryDidChangeNotification
59                                                   object:nil];
60     
61 }
62 
63 - (IBAction)changeBodySelectedColorMatchButtonBackgroundColor:(UIButton *)sender {
64     [self.body.textStorage addAttribute:NSForegroundColorAttributeName
65                                   value:sender.backgroundColor
66                                   range:self.body.selectedRange];
67 }
68 
69 - (IBAction)outlineBodySelection {
70     [self.body.textStorage addAttributes:@{NSStrokeWidthAttributeName:@-3,
71                                            NSStrokeColorAttributeName:[UIColor blackColor]}
72                                    range:self.body.selectedRange];
73 }
74 
75 - (IBAction)unoutlineBodySelection {
76     [self.body.textStorage removeAttribute:NSStrokeWidthAttributeName
77                                      range:self.body.selectedRange];
78 }
79 
80 
81 - (void)didReceiveMemoryWarning {
82     [super didReceiveMemoryWarning];
83     // Dispose of any resources that can be recreated.
84 }
85 
86 @end
87 
88  

 

第5课源代码

原文:http://www.cnblogs.com/startiOS/p/5002038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!