Skip to content

Instantly share code, notes, and snippets.

@amadeu01
Last active September 28, 2018 19:45
Show Gist options
  • Save amadeu01/1f6a7aac328631dbcf10939b4e89c861 to your computer and use it in GitHub Desktop.
Save amadeu01/1f6a7aac328631dbcf10939b4e89c861 to your computer and use it in GitHub Desktop.
Calculator UI
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