Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created January 19, 2016 03:57
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/be820245697abc304373 to your computer and use it in GitHub Desktop.
Save quangtqag/be820245697abc304373 to your computer and use it in GitHub Desktop.
import UIKit
class CheckBox: UIButton {
let roundedRectStrokeColor = UIColor.GBTint()
let roundedRectFillColor = UIColor.whiteColor()
let checkmarkColor = UIColor.greenColor()
override func drawRect(rect: CGRect) {
super.drawRect(rect)
//
// Draw checkbox with OFF state
//
let lineWidth:CGFloat = rect.size.width / 10
let roundedRect = UIBezierPath(roundedRect: CGRectInset(rect, lineWidth/2, lineWidth/2), cornerRadius: 5)
roundedRect.lineWidth = lineWidth
roundedRectStrokeColor.setStroke()
roundedRect.stroke()
roundedRectFillColor.setFill()
roundedRect.fill()
//
// Draw checkbox with ON state
//
// Draw check mark
if selected {
let checkmark = UIBezierPath()
let size = rect.size
checkmark.moveToPoint(CGPoint(x: 22/100 * size.width, y: 52/100 * size.height))
checkmark.addLineToPoint(CGPoint(x: 38/100 * size.width, y: 68/100 * size.height))
checkmark.addLineToPoint(CGPoint(x: 76/100 * size.width, y: 30/100 * size.height))
checkmark.lineWidth = lineWidth
checkmarkColor.setStroke()
checkmark.stroke()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment