IOS7筆記-5、視圖控制器生命週期

來源:互聯網
上載者:User

標籤:

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:NSStrokeWidthAttributeName13                                      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)usePerferredFont2 {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)animated11 {12     [super viewWillDisappear:animated];13     [[NSNotificationCenter defaultCenter] removeObserver:self14                                                     name:UIContentSizeCategoryDidChangeNotification15                                                   object:nil];16 }17 18 -(void)perferredFontChanged:(NSNotification *)notification19 {20     [self usePerferredFont];21 }22 23 -(void)usePerferredFont24 {25     self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];26     self.headline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];27 }

5、viewDidLoad中設定初始化執行個體相關,viewWillAppear則表示與介面相關已經初始化完畢,若有需要耗時資源則亦放置在viewWillAppear中實現!

IOS7筆記-5、視圖控制器生命週期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.