Skip to content

Instantly share code, notes, and snippets.

@ashour
Last active April 9, 2019 13:16
Show Gist options
  • Save ashour/5b6256c97f5d34ed8a77604ee8a9642a to your computer and use it in GitHub Desktop.
Save ashour/5b6256c97f5d34ed8a77604ee8a9642a to your computer and use it in GitHub Desktop.
import UIKit
@IBDesignable
class FlippableUIButton: UIButton
{
var _flipImageForRTL: Bool = false
@IBInspectable
var flipImageForRightToLeftLanguages: Bool
{
get { return _flipImageForRTL }
set { _flipImageForRTL = newValue }
}
override func awakeFromNib() {
if (Locale.current.isRightToLeft)
{
flipAllEdgeInsets()
if (flipImageForRightToLeftLanguages)
{
flipImage()
}
}
}
// ...
fileprivate func flipImage() -> Void
{
if let image = imageView?.image
{
let flippedImage = UIImage(
cgImage: image.cgImage!,
scale: image.scale,
orientation: .upMirrored)
setImage(flippedImage, for: .normal)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment