Created
January 19, 2016 03:57
-
-
Save quangtqag/be820245697abc304373 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
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