Last active
February 26, 2019 13:51
-
-
Save noxt/a2b42361deb51647a44f2519de17b70f to your computer and use it in GitHub Desktop.
UIView+Margins
This file contains 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
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