Skip to content

Instantly share code, notes, and snippets.

@noxt
Last active February 26, 2019 13:51
Show Gist options
  • Save noxt/a2b42361deb51647a44f2519de17b70f to your computer and use it in GitHub Desktop.
Save noxt/a2b42361deb51647a44f2519de17b70f to your computer and use it in GitHub Desktop.
UIView+Margins
import UIKit
public extension UIView {
public func changeMargings(insets: UIEdgeInsets) {
if #available(iOS 11, *) {
directionalLayoutMargins = NSDirectionalEdgeInsets(top: insets.top, leading: insets.left, bottom: insets.bottom, trailing: insets.right)
} else {
layoutMargins = insets
}
}
public func changeMargins(inset: CGFloat) {
changeMargings(insets: UIEdgeInsets(top: inset, left: inset, bottom: inset, right: inset))
}
public func changeMargins(horizontal: CGFloat, vertical: CGFloat) {
changeMargings(insets: UIEdgeInsets(top: vertical, left: horizontal, bottom: vertical, right: horizontal))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment