SWSegmentedControl
一个类似 Android 的标签栏,用 Swift 编写的对 UISegmentedControl 的直接替换。
要求
需要 iOS 8.0 和 ARC。
安装
SWSegmentedControl 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到 Podfile 中
pod "SWSegmentedControl"
用法
SWSegmentedControl 只能通过代码初始化,因为 @IBDesignable 的限制,它不能生成数组,就像 UISegmentedControl 能做的,但我还是让它在需要的时候能渲染。
基本用法
let sc = SWSegmentedControl(items: ["A", "B", "C"])
sc.frame = CGRect(x: 0, y: 0, width: 300, height: 44)
sc.selectedSegmentIndex = 2 // default to 0
编程更改段落
直接设置属性将直接更改段落而无需动画
sc.selectedSegmentIndex = 1
如果您想对动画有更精细的控制,可以使用setSelectedSegmentIndex(index: Int, animated: Bool)
sc.setSelectedSegmentIndex(1, animated: true)
自定义
默认情况下,文本和指示器颜色与tintColor
相同。如果您想独立更改主题,可以使用titleColor
和indicatorColor
,您还可以通过设置font
来更改字体。
作者
Sarun Wongpatcharapakorn ([email protected]) Twitter: @sarunw
许可
SWSegmentedControl在MIT许可下可用。有关更多信息,请参阅LICENSE文件。