iOS成長之AutoLayout寫控制項的注意事項

2021-07-09 08:29:43 字數 1087 閱讀 2734

本篇部落格主要總結,在使用autolayout寫控制項時的注意事項。

step 1,重寫+ (bool)requiresconstraintbasedlayout; 方法,返回yes。這樣預設就是使用自動布局。

- (bool)requiresconstraintbasedlayout

step 2,元件位置,樣式變化等

1. 重寫- (void)updateconstraints;元件位置,大小的變化在這個方法裡面寫。

- (void)updateconstraints
觸發方法

- (void)togglebuttonposition ];

}

下面是**事例。摘自masonry ios examples

//

// ma***ampleremakeview.m

// masonry ios examples

//// created by sam symons on 2014-06-22.

//#import "ma***ampleremakeview.h"

@inte***ce

ma***ampleremakeview ()

@property (nonatomic, strong) uibutton *movingbutton;

@property (nonatomic, assign) bool topleft;

- (void)togglebuttonposition;

@end

@implementation

ma***ampleremakeview

- (id)init

+ (bool)requiresconstraintbasedlayout

- (void)updateconstraints

else

}];[super updateconstraints];

}- (void)togglebuttonposition ];

}@end

iOS 之系統的autoLayou自動t布局

在storyboard中自動布局時,要注意內容吸附優先順序的問題,數值越大,優先順序越高,就越能保持住本身的樣子 約束新增的原則 約束新增到父view上,如果沒有父view,可以新增到共同的父別上 也就是爺爺輩,依次網上推 如果是寬度,高度可以新增到自己身上。import viewcontrolle...

IOS成長之路 NSDate

cpp view plain copy 建立乙個時間物件 nsdata date nsdate date 列印時間 nslog today is date 再獲取的時間date減去24小時的時間 昨天的這個時候 nsdate yesterday nsdate datewithtimeinterval...

IOS成長之路 UIDatePicker 控制項

在 h 中定義控制項,uidatepicker datepicker property strong,nonatomic uidatepicker datepicker m 中實現 使用備份變數名 synthesize datepicker datepicker 設定控制項 初始化uidatepic...