Last active
August 29, 2015 14:08
-
-
Save morizotter/dc8278f130ac70808891 to your computer and use it in GitHub Desktop.
AutoLayoutをSwiftで簡潔に記述できるSnappyを試してみた ref: http://qiita.com/morizotter/items/0856e5614486df65eee6
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
import UIKit | |
import Snappy | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// FULL SCREEN VIEW [BLUE] | |
let blueView = UIView() | |
blueView.backgroundColor = UIColor.blueColor() | |
self.view.addSubview(blueView) | |
blueView.snp_makeConstraints { make in | |
make.edges.equalTo(self.view) | |
return | |
} | |
// PADDING ALL EDGES [ORANGE] | |
let orangeView = UIView() | |
orangeView.backgroundColor = UIColor.orangeColor() | |
self.view.addSubview(orangeView) | |
let orangeViewPadding = UIEdgeInsetsMake(10, 10, 10, 10) | |
orangeView.snp_makeConstraints { make in | |
make.edges.equalTo(self.view).with.insets(orangeViewPadding) | |
return | |
} | |
// VIEW ON PADDING VIEW [GREEN] | |
let greenView = UIView() | |
greenView.backgroundColor = UIColor.greenColor() | |
orangeView.addSubview(greenView) | |
let greenViewPadding = UIEdgeInsetsMake(0.0, 0.0, 150.0, 10.0) | |
greenView.snp_makeConstraints { make in | |
make.top.equalTo(orangeView.snp_top).with.offset(greenViewPadding.top) | |
make.left.equalTo(orangeView.snp_left).with.offset(greenViewPadding.left) | |
make.bottom.equalTo(orangeView.snp_bottom).with.offset(-greenViewPadding.bottom) | |
make.right.equalTo(orangeView.snp_right).with.offset(-greenViewPadding.right) | |
return | |
} | |
} | |
} | |
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
let blueView = UIView() | |
blueView.backgroundColor = UIColor.blueColor() | |
self.view.addSubview(blueView) | |
blueView.snp_makeConstraints { make in | |
make.edges.equalTo(self.view) | |
return | |
} |
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
let orangeView = UIView() | |
orangeView.backgroundColor = UIColor.orangeColor() | |
self.view.addSubview(orangeView) | |
let orangeViewPadding = UIEdgeInsetsMake(10, 10, 10, 10) | |
orangeView.snp_makeConstraints { make in | |
make.edges.equalTo(self.view).with.insets(orangeViewPadding) | |
return | |
} |
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
git clone [email protected]:morizotter/MZRSnappySample.git | |
git submodule init | |
git submodule update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment