斯坦福大學-IOS7應用開發總結

來源:互聯網
上載者:User

標籤:des   style   blog   io   ar   color   os   使用   sp   

Lecture 4

1. 如果某個常值內容的字型需要根據使用者的設定來調整大小的話,我們可以選用如下方法來設定該文本的字型:

[UIFont preferredFontForTextStyle:UIFontTextStyleBody];//而不是如下固定的使用系統字型[UIFont systemFontOfSize:12];

2. 使用UIFontDescriptor類來為現有字型添加額外的屬性:

UIFont *bodyFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];UIFontDescriptor *existingDescriptor = [bodyFont fontDescriptor];UIFontDescriptorSymbolicTraits traits = existingDescriptor.symbolicTraits;traits |= UIFontDescriptorTraitBold;UIFontDescriptor *newDescriptor = [existingDescriptor fontDescriptorWithSymbolicTraits:traits];UIFont *boldBodyFont = [UIFont fontWithDescriptor:newDescriptor size:0];//0為任意大小

3. 通過NSMutableAttributedString類給文本添加樣式:

UIColor *yellow = [UIColor yellowColor];UIColor *transparentYellow = [yellow colorWithAlphaComponent:0.3]; @{ NSFontAttributeName :      [UIFont preferredFontWithTextStyle:UIFontTextStyleHeadline]   NSForegroundColorAttributeName : [UIColor greenColor],   NSStrokeWidthAttributeName : @-5,   NSStrokeColorAttributeName : [UIColor redColor],   NSUnderlineStyleAttributeName : @(NSUnderlineStyleNone),   NSBackgroundColorAttributeName : transparentYellow }// UIButton’s - (void)setAttributedTitle:(NSAttributedString *)title forState:...; // UILabel’s @property (nonatomic, strong) NSAttributedString *attributedText; // UITextView’s @property (nonatomic, readonly) NSTextStorage *textStorage;

Lecture 5

1.View Controller lifeCycle

//在控制器初始化完成並且outlet被設定後調用
- (void)viewDidLoad{[super viewDidLoad]; // always let super have a chance in lifecycle methods// do some setup of my MVC}
//此方法需要注意的是在來到這個方法時,視圖的大小還沒有確定,即view的frame還是未知的,因此不要在此方法裡面做一些初始化size的操作。
// 在視圖即將顯示在螢幕上時調用- (void)viewWillAppear:(BOOL)animated;// 注意:此方法隨著視圖的顯示與隱藏會調用多次,而視圖只loaded一次,因為不要在這裡面做太多事情,如果是會經常變化的操作,可以在此方法中。
// 在視圖即將消失時調用- (void)viewWillDisappear:(BOOL)animated{[super viewWillDisappear:animated];}// 一般在此方法中做一些代碼清理工作,釋放記憶體
// 在view的frame被改變或其subviews改變的任務時候都會被調用- (void)view{Will,Did}LayoutSubviews;// 一般設定視圖或子視圖的frame操作都在此方法中進行
// 當使用storyboard建立視圖控制器時,在outlet被設定之前會調用此方法- (void)awakeFromNib{}// 注意的是,如果視圖控制器是在storyboard建立,將不會再調用預設的初始化方法,所以一些初始化的操作應該放在此方法中來執行。

 Lecture 8

1. Dynamic Animation

建立動態動畫:重力、碰撞。步驟:

a. 建立一個UIDynamicAnimator對象

b. 添加一個行為對象UIDynamicBehaviors(一般是其子類:重力gravity、碰撞collisions、吸附attachment等)

c. 添加一個UIDynamicItems(一般是UIViews)到上面的行為對象中

如:

UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:aView];UIGravityBehavior *gravity = [[UIGravityBehavior alloc] init]; [animator addBehavior:gravity];UICollisionBehavior *collider = [[UICollisionBehavior alloc] init]; [animator addBehavior:collider];id <UIDynamicItem> item1 = ...; id <UIDynamicItem> item2 = ...; [gravity addItem:item1]; [collider addItem:item1];[gravity addItem:item2];

任務對象都可以作為UIDynamicItem,前提是需要實現<UIDynamicItem>協議。UIView預設實現了此協議。

其中,我們也可以建立自訂的UIDynamicBehavior對象(它是所有行為的父類),在初始化方法中添加想要添加的行為(可以多個),這樣就能實現將多個子行為動畫的封裝。通過下面的方法可以添加子行為:

- (void)addChildBehavior:(UIDynamicBehavior *)behavior;

當行為被執行時,會調用一個名為actoin的block方法。預設是沒有實現的,如果我們要在此過程做些什麼的話,可以實現該block。

@property (copy) void (^action)(void);

 

 

斯坦福大學-IOS7應用開發總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.