Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created January 19, 2016 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quangtqag/0d0e9b0eff987159492a to your computer and use it in GitHub Desktop.
Save quangtqag/0d0e9b0eff987159492a to your computer and use it in GitHub Desktop.
class RadioBox: UIButton {
var borderColor: UIColor = UIColor.lightGrayColor()
var innerColor: UIColor = UIColor.linkTextColor()
var borderWidthPercent: Int = 40 {
didSet {
borderWidthPercent = max(min(borderWidthPercent, 90), 10)
}
}
override func drawRect(rect: CGRect) {
super.drawRect(rect)
let lineWidth:CGFloat = (rect.size.width / 2) * CGFloat(borderWidthPercent) / 100
//
// Draw border of radiobox
//
let circleBorder = UIBezierPath(ovalInRect: CGRectInset(rect, lineWidth/2, lineWidth/2))
circleBorder.lineWidth = lineWidth
borderColor.setStroke()
circleBorder.stroke()
//
// Draw inner circle if state is selected
//
if selected == true {
let innerCircle = UIBezierPath(ovalInRect: CGRectInset(rect, lineWidth, lineWidth))
innerColor.setFill()
innerCircle.fill()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment