Skip to content

Instantly share code, notes, and snippets.

@ashour
Last active April 9, 2019 17:28
Show Gist options
  • Save ashour/68e44d519e2f3e8e7ab949d7320ea550 to your computer and use it in GitHub Desktop.
Save ashour/68e44d519e2f3e8e7ab949d7320ea550 to your computer and use it in GitHub Desktop.
import UIKit
class FlippableUIButton: UIButton
{
override func awakeFromNib()
{
if (Locale.current.isRightToLeft)
{
flipAllEdgeInsets()
}
}
fileprivate func flipAllEdgeInsets() -> Void
{
flip(edgeInsets: &contentEdgeInsets)
flip(edgeInsets: &titleEdgeInsets)
flip(edgeInsets: &imageEdgeInsets)
}
fileprivate func flip(edgeInsets: inout UIEdgeInsets) -> Void
{
let leftEdgeInset = edgeInsets.left
edgeInsets.left = edgeInsets.right
edgeInsets.right = leftEdgeInset
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment