(5/18) Re-learning STANDFORD_IOS7 Development _ View Controller life Cycle _ Course Notes

Source: Internet
Author: User

Lesson Five:

1, Uitextview

@property (Nonatomic,ReadOnly) Nstextstorage *textstorage;//Note As a read-only property, you cannot change the contents directly, Nstextstorage is a subclass of nsmutableattributestring, so you can change the string property contents (not the string)//For example, adding a property[Self.body.textStorage addattribute:nsforegroundcolorattributename value:sender.backg Roundcolor Range:self.body.selectedRange]; @property (nonatomic, strong) Uifont*font;//for example, adding fontsSelf.body.font =[Uifont Preferredfontfortextstyle:uifonttextstylebody]; Self.headLine.font=[Uifont preferredfontfortextstyle:uifonttextstyleheadline];//text layout function, text mixing and so on@property (ReadOnly) Nstextcontainer *TextContainer; @property (ReadOnly) Nslayoutmanager *layoutmanager;

2. View Controller Lifecycle

-(Instancetype) Initwithnibname: (NSString *) name Bundle: (NSBundle *) bundle;//non-storyboard loading mode, specifying initializer- (void) awakefromnib;//called when the UI is loaded from storyboard, the output port is not set at this time//Setting the output port- (void) Viewdidload;//Controller Initialization code (one-time) can be placed, such as Init. Cannot place geometry-related code when UI boundaries in the controller are not determined//Determine geometry layout//called when the view frame changes, where it is appropriate to add geometry-related code- (void) viewwilllayoutsubviews;- (void) viewdidlayoutsubviews;//other APIs on screen rotation ...- (void) Viewwillappear: (BOOL) animated;//may be called repeatedly in the life cycle, so it is not possible to place one-time initialization content- (void) Viewdidappear: (BOOL) animated;- (void) Viewwilldisappear: (BOOL) animated;//can do some current data saving work- (void) Viewdiddisappear: (BOOL) animated;- (void) didreceivememorywarning;//system is called when memory is low

3, Nsnotification

(This lesson only covers how to listen to notifications)

[Nsnotificationcenter Defaultcenter];//Get Defaultcenter//Add Observer- (void) Addobserver: (ID) Observer//the object that receives the notificationselector: (SEL) methodtoinvokeifsomethinghappens name: (NSString*) name//Broadcast name                    Object:(ID) sender;//listen to the broadcast object, nil refers to listen to all objects//call method after receiving notification- (void) Methodtoinvokeifsomethinghappens: (Nsnotification *) notification{Notification.name//The name passed aboveNotification.Object //send a Broadcast objectNotification.userinfo//notification-specific information about what happened (depending on sender)}//end Listen notification, usually placed when the view disappears from the interface[center removeobserver:self]; [Center removeobserver:self Name:uicontentsizecategorydidchangenotificationObject: nil];

Notification instance (System settings font change)

//The view appears on the screen to register the notification- (void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (preferredfontchanged:) Name: UicontentsizecategorydidchangenotificationObject: nil];}//Invoke method when notification occurs- (void) preferredfontchanged: (Nsnotification *) notification{[self usepreferredfonts];}//re-set font- (void) usepreferredfonts{Self.body.font=[Uifont Preferredfontfortextstyle:uifonttextstylebody]; Self.headLine.font=[Uifont preferredfontfortextstyle:uifonttextstyleheadline];}//view left interface is removal notification- (void) Viewwilldisappear: (BOOL) animated{[Super viewwilldisappear:animated]; [[Nsnotificationcenter Defaultcenter] removeobserver:self Name:uiconten TsizecategorydidchangenotificationObject: nil];

4. Homework

No

Course Example Attributor Source: https://github.com/NSLogMeng/Stanford_iOS7_Study/commit/242826c2220afe978bc1d060c2dff19578a835c9

Course Video Address: NetEase Open class: Http://open.163.com/movie/2014/1/L/H/M9H7S9F1H_M9H801GLH.html

or itunes U search Standford Course

(5/18) Re-learning STANDFORD_IOS7 Development _ View Controller life Cycle _ Course Notes

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.