Rightpoint/Swiftilities

Add UIEdgeInsets utilities

jvisenti opened this issue · 3 comments

extension UIEdgeInsets {

    init(inset: CGFloat) {
        self.init(top: inset, left: inset, bottom: inset, right: inset)
    }

    init(xInset: CGFloat, yInset: CGFloat) {
        self.init(top: yInset, left: xInset, bottom: yInset, right: xInset)
    }

    init(top: CGFloat) {
        self.init(top: top, left: 0.0, bottom: 0.0, right: 0.0)
    }

    init(left: CGFloat) {
        self.init(top: 0.0, left: left, bottom: 0.0, right: 0.0)
    }

    init(bottom: CGFloat) {
        self.init(top: 0.0, left: 0.0, bottom: bottom, right: 0.0)
    }

    init(right: CGFloat) {
        self.init(top: 0.0, left: 0.0, bottom: 0.0, right: right)
    }

}

Note that this makes it impossible to use UIEdgeInsets(), because it's ambiguous. Not a huge problem, since UIEdgeInsetsZero exists, but worth considering.

We should revisit my previous comment for Swift 3, because I bet UIEdgeInsetsZero is going away due to the Great Renaming. Not sure what's replacing it, though.

Not a ton of value here, closing