Skip to content

Instantly share code, notes, and snippets.

@fabnoe
Last active August 29, 2015 14:05
Show Gist options
  • Save fabnoe/bbf9545769d4a149faae to your computer and use it in GitHub Desktop.
Save fabnoe/bbf9545769d4a149faae to your computer and use it in GitHub Desktop.
Draws a button with the image on the right hand side of the label
import UIKit
class ReversedUIButton: UIButton {
var buffer:NSNumber = 5
override func layoutSubviews() {
super.layoutSubviews()
let imageSize:CGSize = self.imageView.frame.size
let titleSize:CGSize = self.titleLabel.frame.size
var imageFrame:CGRect = self.imageView.frame
imageFrame.origin.x = self.bounds.origin.x + self.frame.size.width - imageSize.width
self.imageView.frame = imageFrame
var labelFrame = self.titleLabel.frame
labelFrame.origin.x = imageFrame.origin.x - labelFrame.width - buffer
self.titleLabel.frame = labelFrame
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment