IOS7 notes-5, view controller life cycle

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.