Skip to content

Instantly share code, notes, and snippets.

@dennislysenko
Created March 27, 2018 19:04
Show Gist options
  • Save dennislysenko/7aa675ed83f2c02f91bbe2bf29c574de to your computer and use it in GitHub Desktop.
Save dennislysenko/7aa675ed83f2c02f91bbe2bf29c574de to your computer and use it in GitHub Desktop.
Tiny set of helpers to make autoresizing-mask-based programmatic UI prototyping more palatable.
import UIKit
public extension UIView {
public var width: CGFloat {
set {
bounds.size.width = newValue
}
get {
return bounds.size.width
}
}
public var height: CGFloat {
set {
bounds.size.height = newValue
}
get {
return bounds.size.height
}
}
public var x: CGFloat {
set {
frame.origin.x = newValue
}
get {
return frame.origin.x
}
}
public var y: CGFloat {
set {
frame.origin.y = newValue
}
get {
return frame.origin.y
}
}
public var maxX: CGFloat {
set {
frame.origin.x = newValue - width
}
get {
return frame.origin.x + width
}
}
public var maxY: CGFloat {
set {
frame.origin.y = newValue - height
}
get {
return frame.origin.y + height
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment