Skip to content

Instantly share code, notes, and snippets.

@harmittaa
Created October 5, 2017 06:18
Show Gist options
  • Save harmittaa/a5d4ef1cf00cd94e79be1d3b8490021c to your computer and use it in GitHub Desktop.
Save harmittaa/a5d4ef1cf00cd94e79be1d3b8490021c to your computer and use it in GitHub Desktop.
UIButton with label and right aligned image
import UIKit
class ButtonWithImage: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
if imageView != nil {
imageEdgeInsets = UIEdgeInsets(top: 5, left: (bounds.width - 35), bottom: 5, right: 5)
titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: (imageView?.frame.width)!)
}
}
}
@Sjahriyar
Copy link

if let imageView = imageView {
// ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment