码迷,mamicode.com
首页 > 移动开发 > 详细

IOS7笔记-5、视图控制器生命周期

时间:2016-06-05 16:56:19      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

1、字体属性的添加方法

 1 - (IBAction)changeBodySelectedColorMatchBackgroundOfButton:(UIButton *)sender {
 2     [self.body.textStorage addAttribute:NSForegroundColorAttributeName
 3                                   value:sender.backgroundColor
 4                                   range:self.body.selectedRange];
 5 }
 6 
 7 - (IBAction)outlineBodySelection {
 8     [self.body.textStorage addAttributes:@{NSStrokeWidthAttributeName: @-3,
 9                                            NSStrokeColorAttributeName: [UIColor blackColor]} range:self.body.selectedRange];
10 }
11 - (IBAction)unOutlineBodySelection {
12     [self.body.textStorage removeAttribute:NSStrokeWidthAttributeName
13                                      range:self.body.selectedRange];
14 }

2、按钮字体描边设置,一般在viewDidLoad中实现

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     // Do any additional setup after loading the view, typically from a nib.
 5     NSMutableAttributedString *title =
 6     [[NSMutableAttributedString alloc] initWithString:self.outlineButton.currentTitle];
 7     [title setAttributes:@{NSStrokeWidthAttributeName: @3,
 8                            NSStrokeColorAttributeName: self.outlineButton.tintColor}
 9                    range:NSMakeRange(0, [title length])];
10     [self.outlineButton setAttributedTitle:title forState:UIControlStateNormal];
11 }

3、使用用户设置的字体

1 -(void)usePerferredFont
2 {
3     self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
4     self.headline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
5 }

4、添加广播与去除广播一般分别在viewWillAppear和viewWillDisappear中设置

 1 -(void)viewWillAppear:(BOOL)animated
 2 {
 3     [super viewWillAppear:animated];
 4     [self usePerferredFont];
 5     [[NSNotificationCenter defaultCenter] addObserver:self
 6                                              selector:@selector(perferredFontChanged:)
 7                                                  name:UIContentSizeCategoryDidChangeNotification object:nil];
 8 }
 9 
10 -(void)viewWillDisappear:(BOOL)animated
11 {
12     [super viewWillDisappear:animated];
13     [[NSNotificationCenter defaultCenter] removeObserver:self
14                                                     name:UIContentSizeCategoryDidChangeNotification
15                                                   object:nil];
16 }
17 
18 -(void)perferredFontChanged:(NSNotification *)notification
19 {
20     [self usePerferredFont];
21 }
22 
23 -(void)usePerferredFont
24 {
25     self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
26     self.headline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
27 }

5、viewDidLoad中设置初始化实例相关,viewWillAppear则表示与界面相关已经初始化完毕,若有需要耗时资源则亦放置在viewWillAppear中实现!

IOS7笔记-5、视图控制器生命周期

标签:

原文地址:http://www.cnblogs.com/jonathan236/p/5560956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!