Skip to content

Instantly share code, notes, and snippets.

@prat14k
Forked from harmittaa/ButtonWithImage.swift
Last active July 27, 2018 11:02
Show Gist options
  • Save prat14k/42bb02d1b31d64043391a419e29537df to your computer and use it in GitHub Desktop.
Save prat14k/42bb02d1b31d64043391a419e29537df to your computer and use it in GitHub Desktop.
UIButton with label and right aligned image(adjacent to the border)
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)!)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment