- iOS 10.0
- Swift 4.x
- Xcode 10
记录了初版实现思路的文章 掘金
YDChannelSelector is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'YDChannelSelector'
直接拖YDChannelSelector进入项目
-
支持本地缓存用户操作
-
界面逻辑基本1:1 还原网易新闻 扩展性强 自定义性强
-
纯净无任何依赖耦合 接口和tableView类似 容易上手
-
注释思路详尽 不管是自己定制还是参考思路或者直接使用都没问题
-
支持cocoapods或者直接拖入项目使用
-
网易后续界面逻辑同步更新
创建频道选择器只需要三个参数: 代理,是否缓存用户操作(默认缓存),数据源(网络获取到后再赋值即可)
private lazy var channelSelector: YDChannelSelector = {
let cv = YDChannelSelector()
cv.dataSource = self
cv.delegate = self
// 是否支持本地缓存用户功能
// cv.isCacheLastest = false
return cv
}()
SelectorItem中有三个属性 channelTitle即为频道标题 isFixation 是否是固定栏目 rawData ** 原始数据 模型或者字典皆可 **
public protocol YDChannelSelectorDataSource: class {
func numberOfSections(in selector: YDChannelSelector) -> Int
func selector(_ selector: YDChannelSelector, numberOfItemsInSection section: Int) -> Int
func selector(_ selector: YDChannelSelector, itemAt indexPath: IndexPath) -> SelectorItem
}
.........
直接使用UIViewController的方法present即可
present(channelSelector, animated: true, completion: nil)
// 数据源发生变化
func selector(_ selector: YDChannelSelector, didChangeDS newDataSource: [[SelectorItem]]) {
print(newDataSource.map { $0.map { $0.channelTitle! } })
}
// 用户退出操作时
func selector(_ selector: YDChannelSelector, dismiss newDataSource: [[SelectorItem]]) {
print(newDataSource.map { $0.map { $0.channelTitle! } })
}
// 用户选中新频道时
func selector(_ selector: YDChannelSelector, didSelectChannel channelItem: SelectorItem) {
print(channelItem.channelTitle!)
}
yd2008, 332838156@qq.com
YDChannelSelector is available under the MIT license. See the LICENSE file for more info.