ABChoiceView
ABChoiceView 是一个用 Swift 编写的自定义视图库,适用于 iOS 9.1+
ABChoiceView 十分灵活且可自定义。它可以用于不同的尺寸和形状,其中的每个功能都是模块化的。
默认情况下,ChoiceView 看起来像这样
当选中时
choiceView.checked == true您可以更改勾选项图像
choiceView.checkImage = UIImage(named: "check_x")并添加一个蒙版
choiceView.maskWhenChecked == true无图像和不同字体
choiceView.image = nil
choiceView.font = UIFont(name: "Courier", size: 30.0)无文本
choiceView.text = nil不同大小
边框和蒙版也可自定义
安装
CocoaPods
根据您的 Swift 版本,请在 Podfile 中添加以下其中一行
target 'MyApp' do
pod 'ABChoiceView', '~> 1.0.2'
endCarthage
根据您的 Swift 版本,请在 Cartfile 中添加以下其中一行
github "avivbenshabat/ABChoiceView"Usage
Interface Builder(可能与 Carthage 不兼容)
将 UIView 拖动到 storybook 中。打开 Identity Inspector,将 ABChoiceView 设置为类和模块。
代码
choiceView.image = UIImage(named: "banana")
choiceView.text = "Banana"
choiceView.font = UIFont(name: "Courier", size: 18)
choiceView.checkImage = UIImage(named: "x_icon")
choiceView.borderPolicy = .noDashes // default is "dashedWhenUnchecked"
choiceView.maskWhenChecked = true // default is false
choiceView.maskData = DiagonalBackgroundView.Data(lineWidth: 3.0, spacing: 5.0, lineColor: .gray, backgroundColor: .darkGray)您也可以设置一个代表
choiceView.id = "13"
choiceView.delegate = selffunc onViewStateChange(checked: Bool, id: String?) {
// Do something...
}或一个闭包
choiceView.id = "13"
choiceView.clicked = { [weak self] checked, id in
// Do something...
}注意:如果您没有设置 ID,回调将返回视图的文本作为 ID。如果视图是仅图像,则将返回 nil








