標籤:
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、視圖控制器生命週期