TZSegmentedControl
Hesham Megid 的 HMSegmentedControl 的 Swift 实现。它是 UISegmentedControl 的嵌入替代品,模仿了 Google Currents 和其他各种 Google 产品中使用的分段控制按钮的样式。
示例
要运行示例项目,首先克隆仓库,然后从示例目录中运行 pod install
。
要求
- Swift 4.2 以上
- iOS 10 以上
安装
TZSegmentedControl 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中。
pod "TZSegmentedControl"
使用
请查看示例项目中的代码,了解如何自定义 TZSegmentedControl。
创建新的 TZSegmentedControl
let titleCont = TZSegmentedControl(sectionTitles: ["TRENDING","EDITOR'S PICKS", "FOR YOU", "VIDEOS", "LANGUAGE" ])
titleCont.frame = CGRect(x: 0, y: 50, width: self.view.frame.width, height: 50)
TZSegmentedControl 还提供一个在选定索引变化时执行的块。或者,你可以使用 addTarget:action:forControlEvents:
titleCont.indexChangeBlock = { (index) in
debugPrint("Segmented \(titleCont.sectionTitles[index]) is visible now")
}
截图
作者
[email protected][email protected]
许可证
TZSegmentedControl 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。
感谢
感谢 Hesham Megid,他的 HMSegmentedControl 代码非常有帮助。