Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created October 18, 2019 13:22
Show Gist options
  • Select an option

  • Save lamprosg/f792f136446974140802a77521ab8fac to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/f792f136446974140802a77521ab8fac to your computer and use it in GitHub Desktop.
(iOS) Button with left title and right image
class SomeButton: UIButton {
override func awakeFromNib() {
super.awakeFromNib()
self.semanticContentAttribute = UIApplication.shared
.userInterfaceLayoutDirection == .rightToLeft ? .forceLeftToRight : .forceRightToLeft
let insetAmount: CGFloat = 4.0
imageEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: -insetAmount)
titleEdgeInsets = UIEdgeInsets(top: 0, left: -insetAmount, bottom: 0, right: insetAmount)
contentEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: insetAmount)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment