mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-01-12 22:47:34 +08:00
50 lines
1.5 KiB
Swift
50 lines
1.5 KiB
Swift
//
|
|
// File.swift
|
|
// Freetime
|
|
//
|
|
// Created by Ryan Nystrom on 4/21/18.
|
|
// Copyright © 2018 Ryan Nystrom. All rights reserved.
|
|
//
|
|
|
|
import IGListKit
|
|
|
|
final class LabelSectionController: ListSwiftSectionController<RepositoryLabel> {
|
|
|
|
public private(set) var selected: Bool
|
|
|
|
init(selected: Bool) {
|
|
self.selected = selected
|
|
super.init()
|
|
}
|
|
|
|
override func createBinders(from value: RepositoryLabel) -> [ListBinder] {
|
|
return [
|
|
binder(
|
|
value,
|
|
cellType: ListCellType.class(LabelMenuCell.self),
|
|
size: {
|
|
return CGSize(
|
|
width: $0.collection.containerSize.width,
|
|
height: Styles.Sizes.tableCellHeightLarge
|
|
)
|
|
},
|
|
configure: { [selected] in
|
|
let color = $1.value.color.color
|
|
$0.button.setTitleColor(color.textOverlayColor, for: .normal)
|
|
$0.button.backgroundColor = color
|
|
$0.button.setTitle($1.value.name, for: .normal)
|
|
|
|
$0.setSelected(selected)
|
|
},
|
|
didSelect: { [weak self] context in
|
|
guard let strongSelf = self else { return }
|
|
strongSelf.selected = !strongSelf.selected
|
|
context.deselect()
|
|
context.cell?.setSelected(strongSelf.selected)
|
|
})
|
|
]
|
|
}
|
|
|
|
}
|
|
|