Slide 1

Slide 1 text

layout of iOS for beginner…

Slide 2

Slide 2 text

storyboard autolayout

Slide 3

Slide 3 text

NSLayoutConstraint

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

2014-08-10 23:48:07.293 autolayoutTest[952:60b] Cannot find executable for CFBundle 0x8e4f910 (not loaded) 2014-08-10 23:48:07.341 autolayoutTest[952:60b] ( "", "", "", "", "<_UILayoutSupportConstraint:0x8d684c0 V:[_UILayoutGuide: 0x8d49d60(0)]>", "<_UILayoutSupportConstraint:0x8d65880 V:|-(0)-[_UILayoutGuide: 0x8d49d60] (Names: '|':UIView:0x8d47260 )>", "<_UILayoutSupportConstraint:0x8d68120 V:[_UILayoutGuide: 0x8d4b5d0(0)]>", "<_UILayoutSupportConstraint:0x8d639f0 _UILayoutGuide: 0x8d4b5d0.bottom == UIView:0x8d47260.bottom>" )

Slide 7

Slide 7 text

UIView *superview = self; ! UIView *view1 = [[UIView alloc] init]; view1.translatesAutoresizingMaskIntoConstraints = NO; view1.backgroundColor = [UIColor greenColor]; [superview addSubview:view1]; ! UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10); ! [superview addConstraints:@[ ! //view1 constraints [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeTop multiplier:1.0 constant:padding.top], ! [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:padding.left], ! [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-padding.bottom], ! [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeRight multiplier:1 constant:-padding.right], ! ]];

Slide 8

Slide 8 text

Visual Format rview Constraint constraintsWithVisualFormat:@"|[headerView]|" options:0 metrics:metrics views:views]]; f the superview Constraint constraintsWithVisualFormat:@"V:|[headerView]" options:0 metrics:metrics views:views]]; out outConstraint constraintsWithVisualFormat:@"|-padding-[headline]-padding-[imageView(imageEdge)]- ews:views]]; - spacing at least zero between the two outConstraint constraintsWithVisualFormat:@"V:|-padding-[headline]->=0-[byline]-padding-|" etrics:metrics views:views]]; spacing at least 15 between the two outConstraint constraintsWithVisualFormat:@"V:|-padding-[imageView(imageEdge)]->=padding-[button]- gnAllLeft | NSLayoutFormatAlignAllRight metrics:metrics views:views]];

Slide 9

Slide 9 text

asos

Slide 10

Slide 10 text

https://github.com/Masonry/Masonry

Slide 11

Slide 11 text

UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10); ! [view1 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(superview.mas_top).with.offset(padding.top); //with is an optional semantic filler make.left.equalTo(superview.mas_left).with.offset(padding.left); make.bottom.equalTo(superview.mas_bottom).with.offset(- padding.bottom); make.right.equalTo(superview.mas_right).with.offset(-padding.right); }];

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "", "", "", "" )

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

use code to generate the view

Slide 16

Slide 16 text

[self.slider makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.centerX); make.bottom.equalTo(self.bottom).multipliedBy(110.0 / 120); make.width.equalTo(self.width).multipliedBy(150.0 / 300); make.height.equalTo(self.height).multipliedBy(25.0 / 120); }];

Slide 17

Slide 17 text

translatesAutoresizingMaskIntoConstraints = NO too many subviews Possible error

Slide 18

Slide 18 text

viewDidAppear

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Font size adjustsfontsizetofitwidth [label.text sizeWithFont:label.font minFontSize:label.minimumFontSize actualFontSize:&actualFontSize forWidth:label.bounds.size.width lineBreakMode:label.lineBreakMode]; if don’t want the font size always change due to length of char sizeToFit

Slide 21

Slide 21 text

Thanks Edwin