轻量级,不使用图像的复选框。
UIControl
的子类。@IBInspectable
。您可以在 Storyboard 中更改颜色、边框。@IBDesignable
。您可以在 storyboard 中看到复选框SUCheckButton 通过 CocoaPods 提供。安装它,只需将以下行添加到您的 Podfile 中
pod "SUCheckButton"
然后运行
pod install
SUCheckButton
属性检查器
进行更改。import SUCheckButton
// Use convenience initializer
let checkButton = SUCheckButton() // make default frame: {0, 0, 30, 30}
// Use normal initializer
let checkButton = SUCheckButton(frame: CGRectMake(0, 0, 44, 44))
// change color
checkButton.checkedFillColor = UIColor(red: 1.0, green: 0.2, blue: 0.1, alpha: 1.0)
// did press handler
checkButton.didPressHandler = { (checked: Bool) in
print("status : \(checked)")
}
// also use addTarget:action:forControlEvents:
checkButton.addTarget(self, action: "checkValueChanged:", forControlEvents: .ValueChanged)
如果只使用标记(不作为按钮使用),设置 userInteractionEnabled = false
checkButton.userInteractionEnabled = false
checkButton.checked = true // status : checked. change mark.
checkButton.checked = false // status : unchecked. change mark.
MIT 许可证。有关更多信息,请参阅 LICENSE 文件。