@SanMao
2015-08-06T00:34:48.000000Z
字数 1956
阅读 1266
UI
//#define ScreenW 320
//#define ScreenH 480
#define ScreenW [UIScreen mainScreen].bounds.size.width
#define ScreenH [UIScreen mainScreen].bounds.size.height
// 创建一个显示在屏幕右下角的按钮
CGFloat buttonW = 100;
CGFloat buttonH = 50;
button.frame = CGRectMake(ScreenW - buttonW, ScreenH - buttonH, buttonW, buttonH);
+ (NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views;
* format :VFL语句
* opts :约束类型
* metrics :VFL语句中用到的具体数值
* views :VFL语句中用到的控件
* 出现了一种新的屏幕适配技术:Sizeclass
UIViewAutoresizingFlexibleLeftMargin
= 1 << 0, UIViewAutoresizingFlexibleRightMargin
= 1 << 2, UIViewAutoresizingFlexibleTopMargin
= 1 << 3, UIViewAutoresizingFlexibleBottomMargin
= 1 << 5 UIViewAutoresizingFlexibleWidth
= 1 << 1, UIViewAutoresizingFlexibleHeight
= 1 << 4, 约束
参照
常见单词
代码实现Autolayout的步骤
- (void)addConstraint:(NSLayoutConstraint *)constraint;
- (void)addConstraints:(NSArray *)constraints;
view.translatesAutoresizingMaskIntoConstraints = NO;
* 添加约束之前,一定要保证相关控件都已经在各自的父控件上
* 不用再给view设置frame
+(id)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c;
* view1 :要约束的控件
* attr1 :约束的类型(做怎样的约束)
* relation :与参照控件之间的关系
* view2 :参照的控件
* attr2 :约束的类型(做怎样的约束)
* multiplier :乘数
* c :常量
同层级view
之间的约束关系,添加到它们的父view上不同层级view
之间的约束关系,添加到他们最近的共同父view上有层次关系的两个view
之间的约束关系,添加到层次较高的父view上