Last active
September 28, 2018 19:45
-
-
Save amadeu01/1f6a7aac328631dbcf10939b4e89c861 to your computer and use it in GitHub Desktop.
Calculator UI
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 PlaygroundSupport | |
| extension UIView { | |
| static func roundedView(x: Int, y: Int) -> UIView { | |
| let customView = UIView() | |
| customView.frame = CGRect( | |
| x: x, y: y, | |
| width: 60, height: 60) | |
| customView.backgroundColor = .green | |
| customView.layer.cornerRadius = customView.frame.width/2 | |
| return customView | |
| } | |
| } | |
| class MyViewController : UIViewController { | |
| override func loadView() { | |
| let view = UIView() | |
| view.backgroundColor = .white | |
| view.translatesAutoresizingMaskIntoConstraints = false | |
| self.view = view | |
| } | |
| override func viewDidLoad() { | |
| let roundedView = UIView.roundedView(x: 0, y: 20) | |
| roundedView.translatesAutoresizingMaskIntoConstraints = false | |
| self.view.addSubview(roundedView) | |
| let views = ["roundedView" : roundedView] | |
| let formatString = "|-50-[roundedView(>=30)]-|" | |
| let constraints = NSLayoutConstraint.constraints( | |
| withVisualFormat: formatString, | |
| metrics: nil, | |
| views: views) | |
| NSLayoutConstraint.activate(constraints) | |
| } | |
| } | |
| // Present the view controller in the Live View window | |
| PlaygroundPage.current.liveView = MyViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment