Skip to content

Instantly share code, notes, and snippets.

@shortcircuit3
Created September 29, 2016 05:09
Show Gist options
  • Select an option

  • Save shortcircuit3/4919b387ae9232d6ab1ed913f3c49a0b to your computer and use it in GitHub Desktop.

Select an option

Save shortcircuit3/4919b387ae9232d6ab1ed913f3c49a0b to your computer and use it in GitHub Desktop.
If you're trying to position the title to the left and the icon to the right inside a UIButton
import UIKit
class WorkoutButton: UIButton {
override func imageRectForContentRect(contentRect: CGRect) -> CGRect {
var imageFrame = super.imageRectForContentRect(contentRect)
imageFrame.origin.x = CGRectGetMaxX(contentRect) - CGRectGetWidth(imageFrame)
return imageFrame
}
override func titleRectForContentRect(contentRect: CGRect) -> CGRect {
var titleFrame = super.titleRectForContentRect(contentRect)
if (self.currentImage != nil) {
titleFrame.origin.x = CGRectGetMinX(super.imageRectForContentRect(contentRect))
}
return titleFrame
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment