//
// ViewController.swift
// layout2
//
// Created by MacBookPro on 2017. 11. 16..
// Copyright © 2017년 MacBookPro. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
// view 객체? 만들기
let view_1 = UIView()
let view_2 = UIView()
let view_3 = UIView()
let view_4 = UIView()
let view_5 = UIView()
override func viewDidLoad() {
super.viewDidLoad()
//메인 view에 집어 넣기
view.addSubview(view_1)
view.addSubview(view_2)
view.addSubview(view_3)
view.addSubview(view_4)
view.addSubview(view_5)
//view_1 검정에 대한 설정
view_1.translatesAutoresizingMaskIntoConstraints = false
view_1.backgroundColor = UIColor.black
view_1.widthAnchor.constraint(equalToConstant: view.bounds.size.width - 100).isActive = true
view_1.heightAnchor.constraint(equalToConstant: 100).isActive = true
view_2.translatesAutoresizingMaskIntoConstraints = false
view_2.backgroundColor = UIColor.purple
view_2.widthAnchor.constraint(equalToConstant: 100).isActive = true
view_2.heightAnchor.constraint(equalToConstant: view.bounds.size.height - 100).isActive = true
//view_2를 기준으로 왼쪽에 있는 녀석은~
view_2.leftAnchor.constraint(equalTo: view_1.rightAnchor).isActive = true
view_3.translatesAutoresizingMaskIntoConstraints = false
view_3.backgroundColor = UIColor.brown
view_3.widthAnchor.constraint(equalToConstant: view.bounds.size.width - 100).isActive = true
view_3.heightAnchor.constraint(equalToConstant: 100).isActive = true
view_3.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
view_3.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
view_4.translatesAutoresizingMaskIntoConstraints = false
view_4.backgroundColor = UIColor.blue
view_4.widthAnchor.constraint(equalToConstant: 100).isActive = true
view_4.heightAnchor.constraint(equalToConstant: view.bounds.size.height - 100).isActive = true
//view_4의 위쪽에 있는 녀석은 ~
view_4.topAnchor.constraint(equalTo: view_1.bottomAnchor).isActive = true
view_5.translatesAutoresizingMaskIntoConstraints = false
view_5.backgroundColor = UIColor.yellow
view_5.heightAnchor.constraint(equalToConstant: view.bounds.size.height - 200).isActive = true
view_5.widthAnchor.constraint(equalToConstant: view.bounds.size.width - 200).isActive = true
view_5.topAnchor.constraint(equalTo: view_1.bottomAnchor).isActive = true
view_5.leftAnchor.constraint(equalTo: view_4.rightAnchor).isActive = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
출처: 하울의 코딩채널
'ios 뽀개기 > ios앱' 카테고리의 다른 글
6 데이터 피커 날짜함수 (0) | 2017.11.21 |
---|---|
5 사진 확대 축소 변경 (0) | 2017.11.20 |
4 버튼 action함수 (0) | 2017.11.20 |
3 테이블 뷰 (0) | 2017.11.17 |
1 레이아웃 (0) | 2017.11.16 |
댓글