Skip to content

Instantly share code, notes, and snippets.

@wotjd
Created November 26, 2019 06:52
Show Gist options
  • Save wotjd/823b2ad9a94ec542bd41681c15f5045d to your computer and use it in GitHub Desktop.
Save wotjd/823b2ad9a94ec542bd41681c15f5045d to your computer and use it in GitHub Desktop.
roundable button
import UIKit
class CustomRoundableButton: UIButton {
@IBInspectable var rounded: Bool = false {
didSet { self.updateCornerRadius() }
}
var cornerRadius: CGFloat?
override func layoutSubviews() {
super.layoutSubviews()
self.updateCornerRadius()
}
func updateCornerRadius() {
self.layer.cornerRadius = self.rounded ? self.cornerRadius ?? self.frame.size.height / 2 : 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment