Advertisement
thieumao

Visual String Demo

Dec 5th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.40 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  LearnVisualString
  4. //
  5. //  Created by Thieu Mao on 12/5/16.
  6. //  Copyright © 2016 thieumao. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.  
  13.     override func viewDidLoad() {
  14.         super.viewDidLoad()
  15.         // Do any additional setup after loading the view, typically from a nib.
  16.     }
  17.    
  18.     override func viewDidAppear(_ animated: Bool) {
  19.         super.viewDidAppear(animated)
  20.        
  21.         let newView = UIView()
  22.         newView.backgroundColor = UIColor.red
  23.         self.view.addSubview(newView)
  24.        
  25.         newView.translatesAutoresizingMaskIntoConstraints = false
  26.        
  27.         let views = ["nv" : newView]
  28.         let metrics = ["margins" : 20]
  29.        
  30.         let vContraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-(margins)-[nv]-(margins)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics, views: views)
  31.         let hContraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-(margins)-[nv]-(margins)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics, views: views)
  32.        
  33.         self.view.addConstraints(vContraints)
  34.         self.view.addConstraints(hContraints)
  35.        
  36.     }
  37.  
  38.     override func didReceiveMemoryWarning() {
  39.         super.didReceiveMemoryWarning()
  40.         // Dispose of any resources that can be recreated.
  41.     }
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement