Created
December 22, 2015 02:26
-
-
Save adin283/a6e3be8a14ae2bf96ef3 to your computer and use it in GitHub Desktop.
UIScrollView with AutoLayout by PureLayout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ZZZViewController.m | |
// KevinDemo | |
// | |
// Created by Kevin on 15/12/22. | |
// Copyright © 2015年 KevinLab. All rights reserved. | |
// | |
#import "ZZZViewController.h" | |
@interface ZZZViewController () | |
@property (strong, nonatomic) UIScrollView *scrollView; | |
@property (strong, nonatomic) UIView *view1; | |
@property (strong, nonatomic) UIView *view2; | |
@end | |
@implementation ZZZViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
self.view.backgroundColor = [UIColor whiteColor]; | |
[self.view addSubview:self.scrollView]; | |
[self.scrollView addSubview:self.view1]; | |
[self.scrollView addSubview:self.view2]; | |
[self configureConstraints]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
#pragma mark - Getters | |
- (UIScrollView *)scrollView | |
{ | |
if (!_scrollView) { | |
_scrollView = [[UIScrollView alloc] init]; | |
_scrollView.backgroundColor = [UIColor lightGrayColor]; | |
_scrollView.scrollEnabled = YES; | |
_scrollView.showsVerticalScrollIndicator = YES; | |
} | |
return _scrollView; | |
} | |
- (UIView *)view1 | |
{ | |
if (!_view1) { | |
_view1 = [[UIView alloc] init]; | |
_view1.backgroundColor = [UIColor colorWithHex:0x0a88e3]; | |
} | |
return _view1; | |
} | |
- (UIView *)view2 | |
{ | |
if (!_view2) { | |
_view2 = [[UIView alloc] init]; | |
_view2.backgroundColor = [UIColor colorWithHex:0xCD7320]; | |
} | |
return _view2; | |
} | |
- (void)configureConstraints | |
{ | |
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeTop]; | |
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeBottom]; | |
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeLeft]; | |
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeRight]; | |
[self.view1 autoPinEdgeToSuperviewEdge:ALEdgeTop]; | |
[self.view1 autoPinEdgeToSuperviewEdge:ALEdgeLeft]; | |
[self.view1 autoPinEdgeToSuperviewEdge:ALEdgeRight]; | |
// 确定 contentSize 重要的约束 | |
[self.view1 autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.scrollView]; | |
[self.view1 autoSetDimension:ALDimensionHeight toSize:400]; | |
[self.view2 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.view1]; | |
[self.view2 autoPinEdgeToSuperviewEdge:ALEdgeLeft]; | |
[self.view2 autoPinEdgeToSuperviewEdge:ALEdgeRight]; | |
// 确定 contentSize 重要的约束 | |
[self.view2 autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.scrollView]; | |
[self.view2 autoSetDimension:ALDimensionHeight toSize:800]; | |
// 确定 contentSize 重要的约束 | |
[self.view2 autoPinEdgeToSuperviewEdge:ALEdgeBottom]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment