Created
January 19, 2016 03:55
-
-
Save quangtqag/0d0e9b0eff987159492a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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