Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // LearnVisualString
- //
- // Created by Thieu Mao on 12/5/16.
- // Copyright © 2016 thieumao. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- let newView = UIView()
- newView.backgroundColor = UIColor.red
- self.view.addSubview(newView)
- newView.translatesAutoresizingMaskIntoConstraints = false
- let views = ["nv" : newView]
- let metrics = ["margins" : 20]
- let vContraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-(margins)-[nv]-(margins)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics, views: views)
- let hContraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-(margins)-[nv]-(margins)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics, views: views)
- self.view.addConstraints(vContraints)
- self.view.addConstraints(hContraints)
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement