Created
February 28, 2018 08:09
-
-
Save mukhortov/9a4a7c52eef5968561c4fa842899b3cd to your computer and use it in GitHub Desktop.
Resize UIView Extension.swift
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
// | |
// 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