国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

(5/18)重學Standford_iOS7開發_視圖控制器生命周期_課程筆記

2019-11-14 18:56:33
字體:
來源:轉載
供稿:網友

第五課:

  1、UITextView

@PRoperty (nonatomic, readonly) NSTextStorage *textStorage;//注意為只讀屬性,因此不能直接更改內容,NSTextStorage為NSMutableAttributeString的子類,因此可以更改字符串屬性內容(而非字符串)//例如,添加屬性[self.body.textStorage addAttribute:NSForegroundColorAttributeName                                  value:sender.backgroundColor                                  range:self.body.selectedRange];@property (nonatomic, strong) UIFont *font;//例如添加字體self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];    self.headLine.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];//文本布局功能,如圖文混排等@property (readonly) NSTextContainer *textContainer;@property (readonly) NSLayoutManager *layoutManager;

  2、View Controller Lifecycle 

- (instancetype)initWithNibName:(NSString *)name bundle:(NSBundle *)bundle;//非storyboard加載方式,指定初始化器- (void)awakeFromNib;//從storyboard中加載UI時調用,此時未設置輸出口//設置輸出口- (void)viewDidLoad;//可以放置控制器初始化代碼(一次性),如init。不可放置與幾何相關的代碼,此時控制器中的UI邊界未確定//確定幾何布局//當視圖frame發生變化時就會被調用,此處適合添加與幾何相關的代碼- (void)viewWillLayoutSubviews;- (void)viewDidLayoutSubviews;//其他關于屏幕旋轉等API...- (void)viewWillAppear:(BOOL)animated;//生命周期中可能會被反復調用,因此不能放置一次性初始化內容- (void)viewDidAppear:(BOOL)animated;- (void)viewWillDisappear:(BOOL)animated;//可以進行一些當前數據保存工作- (void)viewDidDisappear:(BOOL)animated;- (void)didReceiveMemoryWarning;//系統在內存不足時調用

  3、NSNotification

(本節課只涉及到如何收聽通知)

[NSNotificationCenter defaultCenter];//獲取defaultCenter//添加觀察者- (void)addObserver:(id)observer //接收通知的對象                  selector:(SEL)methodToInvokeIfsomethingHappens                     name:(NSString *)name //廣播名                    object:(id)sender; //監聽的廣播對象,nil指監聽所有對象//接收到通知后調用方法- (void)methodToInvokeIfSomethingHappens:(NSNotification *)notification{    notification.name // the name passed above    notification.object //發送廣播的對象    notification.userInfo // notification-specific information about what happened(取決于發送者)}//結束收聽通知,通常放于視圖從界面消失時[center removeObserver:self];[center removeObserver:self name:UIContentSizeCategoryDidChangeNotification object:nil];    

通知實例(系統設置字體改變)

//視圖出現在屏幕上注冊通知- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferredFontChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil];}//通知出現時調用方法- (void)preferredFontChanged:(NSNotification *)notification{    [self usePreferredFonts];}//重新設置字體- (void)usePreferredFonts{    self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];    self.headLine.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];}//視圖離開界面是移除通知- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    [[NSNotificationCenter defaultCenter] removeObserver:self                                                    name:UIContentSizeCategoryDidChangeNotification                                                  object:nil];

  4、作業

    無

 

  課程示例Attributor源碼https://github.com/NSLogMeng/Stanford_iOS7_Study/commit/242826c2220afe978bc1d060c2dff19578a835c9

     

課程視頻地址:網易公開課:http://open.163.com/movie/2014/1/L/H/M9H7S9F1H_M9H801GLH.html

       或者iTunes U搜索standford課程


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扎赉特旗| 穆棱市| 遂宁市| 贞丰县| 衡水市| 游戏| 南投市| 长顺县| 双流县| 太仓市| 阳城县| 泸西县| 柞水县| 龙泉市| 万安县| 方山县| 嫩江县| 泾源县| 灵武市| 昌平区| 分宜县| 扶余县| 福清市| 牙克石市| 临猗县| 明光市| 沁阳市| 章丘市| 庆元县| 安阳县| 彭泽县| 从化市| 石城县| 兴安县| 孟连| 蓝山县| 肇东市| 正安县| 兰溪市| 淳安县| 新乐市|