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


    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中实现!

  • 相关阅读:
    Js:getAttribute(转)
    javaScript(1):基础部分
    元信息标签<meta>
    HTML补充:引用脚本、特殊符号、标签、元素、多媒体
    .Net Micro Framework研究—让MF支持英文输入法
    .Net Micro Framework研究系列文章
    .Net Micro Framework研究—实现SideShow窗体界面
    .Net Micro Framework研究—MF驱动继电器
    .Net Micro Framework SDK 2.5 发布
    第二十五章补充内容 9 关键字volatile 简单
  • 原文地址:https://www.cnblogs.com/jonathan236/p/5560956.html
Copyright © 2020-2023  润新知