Skip to content

Instantly share code, notes, and snippets.

@mukhortov
Created February 28, 2018 08:09
Show Gist options
  • Save mukhortov/9a4a7c52eef5968561c4fa842899b3cd to your computer and use it in GitHub Desktop.
Save mukhortov/9a4a7c52eef5968561c4fa842899b3cd to your computer and use it in GitHub Desktop.
Resize UIView Extension.swift
//
// Resize+UIView.swift
//
extension UIView {
func resizeX(_ width: CGFloat) {
for constraint in self.constraints {
if constraint.firstAttribute == NSLayoutAttribute.width && constraint.constant != width {
constraint.constant = width
superview?.layoutIfNeeded()
}
}
}
func resizeY(_ height: CGFloat) {
for constraint in self.constraints {
if constraint.firstAttribute == NSLayoutAttribute.height && constraint.constant != height {
constraint.constant = height
superview?.layoutIfNeeded()
}
}
}
func resize(_ width: CGFloat, height: CGFloat) {
self.resizeX(width)
self.resizeY(height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment