1. How to add font attributes
1-(Ibaction) Changebodyselectedcolormatchbackgroundofbutton: (UIButton *) Sender {2 [Self.body.textStorage addattribute:nsforegroundcolorattributename3 Value:sender.backgroundColor4 Range:self.body.selectedRange];5 }6 7-(ibaction) outlinebodyselection {8[Self.body.textStorage addattributes:@{nsstrokewidthattributename: @-3,9 nsstrokecolorattributename: [Uicolor Blackcolor]} Range:self.body.selectedR Ange];Ten } One-(ibaction) unoutlinebodyselection { A [Self.body.textStorage removeattribute:nsstrokewidthattributename - Range:self.body.selectedRange]; -}
2, button font stroke settings, generally implemented in Viewdidload
1- (void) Viewdidload2 {3 [Super Viewdidload];4 //additional setup after loading the view, typically from a nib.5Nsmutableattributedstring *title =6 [[Nsmutableattributedstring alloc] initWithString:self.outlineButton.currentTitle];7[Title Setattributes:@{nsstrokewidthattributename: @3,8 NSStrokeColorAttributeName:self.outlineButton.tintColor}9Range:nsmakerange (0, [title length]);Ten [Self.outlinebutton setattributedtitle:title forstate:uicontrolstatenormal]; One}
3. Use user-set fonts
1 -(void) useperferredfont2{3 self.body.font = [ Uifont Preferredfontfortextstyle:uifonttextstylebody]; 4 Self.headline.font = [Uifont preferredfontfortextstyle:uifonttextstyleheadline]; 5 }
4. Adding broadcasts and removing broadcasts are generally set in Viewwillappear and Viewwilldisappear respectively
1-(void) Viewwillappear: (BOOL) Animated2 {3 [Super viewwillappear:animated];4 [self useperferredfont];5 [[Nsnotificationcenter Defaultcenter] addobserver:self6 selector: @selector (perferredfontchanged:)7Name:uicontentsizecategorydidchangenotificationObject: nil];8 }9 Ten-(void) Viewwilldisappear: (BOOL) Animated One { A [Super viewwilldisappear:animated]; - [[Nsnotificationcenter Defaultcenter] removeobserver:self - name:uicontentsizecategorydidchangenotification the Object: nil]; - } - --(void) perferredfontchanged: (Nsnotification *) Notification + { - [self useperferredfont]; + } A at-(void) Useperferredfont - { -Self.body.font =[Uifont preferredfontfortextstyle:uifonttextstylebody]; -Self.headline.font =[Uifont preferredfontfortextstyle:uifonttextstyleheadline]; -}
5, Viewdidload set initialization instance correlation, Viewwillappear is said to interface related has been initialized, if need time resources is also placed in viewwillappear implementation!
IOS7 notes-5, view controller life cycle