Skip to content

Instantly share code, notes, and snippets.

@niftycode
Last active November 18, 2015 17:16
Show Gist options
  • Save niftycode/bcea2817f09453f3c7bd to your computer and use it in GitHub Desktop.
Save niftycode/bcea2817f09453f3c7bd to your computer and use it in GitHub Desktop.
UIButton customization in Swift
import UIKit
class MyButton: UIButton {
override var highlighted: Bool {
didSet {
if (highlighted) {
self.backgroundColor = UIColor.redColor()
} else {
self.backgroundColor = UIColor.clearColor()
}
}
}
override func drawRect(rect: CGRect) {
super.drawRect(rect)
self.layer.borderColor = UIColor.whiteColor().CGColor
self.layer.borderWidth = 1.0
self.layer.cornerRadius = 5.0
self.clipsToBounds = true
self.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment