ALRadioButtons
关于
RadioButtons 是从 UIControl 继承的,因此你可以轻松管理它们。
支持两种风格:standard
- 类似于 UITableView plain 风格和 grouped
- 类似于 UITableView insertGrouped 风格
垂直和水平定位。颜色、缩进属性可自定义。
如果你喜欢这个库,请不要忘记给它 ★ star
,这将有助于其发展。
导航
要求
- iOS 10.0 +
- Swift 4.2 +
安装
Swift 包管理器
Swift 包管理器(https://swiftlang.cn/package-manager/)是用于管理 Swift 代码分发的工具。它集成了 Swift 构建系统来自动化下载、编译和链接依赖项的过程。
要集成 ALRadioButtons,请点击 文件 -> Swift 包 -> 添加包依赖项
并插入下面内容:
https://github.com/alxrguz/ALRadioButtons
CocoaPods
ALRadioButtons 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'ALRadioButtons'
手动安装
如果您不希望在项目中使用上述依赖关系管理器,您可以手动集成 ALRadioButtons。将 Source/ALRadioButtons
文件夹放入您的 Xcode 项目中。
用法
快速开始
import ALRadioButtons
class MyViewController: UIViewController {
lazy var radioGroup = ALRadioGroup(items: [
.init(title: "title1", subtitle: "subtitle1"),
.init(title: "title2", subtitle: "subtitle2"),
.init(title: "title3"),
], style: .grouped)
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(radioGroup)
// ... Setup layout
radioGroup.selectedIndex = 0
radioGroup.addTarget(self, action: #selector(radioGroupSelected(_:)), for: .valueChanged)
// If the checkbox selection can be canceled, then set this property to true
radioGroup.allowDeselection = true
}
@objc private func radioGroupSelected(_ sender: ALRadioGroup) {
print(sender.selectedIndex)
}
}
自定义
颜色
您可以自定义按钮、标题和指示器的颜色,具体取决于其状态。
radioGroup.selectedTitleColor = .systemBlue
radioGroup.selectedTitleColor = .black
radioGroup.selectedIndicatorColor = .systemBlue
radioGroup.unselectedIndicatorColor = .systemBlue
radioGroup.subtitleColor = .lightGray
radioGroup.buttonBackgroundColor = .white
radioGroup.separatorColor = .lightGray
字体
radioGroup.titleFont = .systemFont(ofSize: 16, weight: .medium)
radioGroup.subtitleFont = .systemFont(ofSize: 13, weight: .regular)
布局
radioGroup.cornerRadius = 14 // Button corner radius, actual for .grouped style
radioGroup.buttonHeight = 50
radioGroup.subtitleTopOffset = 8 // Subtitle offset from title bottom anchor
radioGroup.separatorTopOffset = 8 // Separator offset from title or subtitle (if added) bottom anchor
radioGroup.indicatorRingWidth = 2 // Outer ring width of indicator
radioGroup.indicatorRingSize = 22 // Indicator outer ring size
radioGroup.indicatorCircleInset = 5 // Indentation of the circle from the outer ring
许可证
ALRadioButtons 采用 MIT 许可协议。有关更多信息,请参阅许可证文件。