123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*****************************************************************************
- * ActionSheetCell.swift
- *
- * Copyright © 2018 VLC authors and VideoLAN
- * Copyright © 2018 Videolabs
- *
- * Authors: Soomin Lee <bubu@mikan.io>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- class ActionSheetCellImageView: UIImageView {
- override var image: UIImage? {
- didSet {
- super.image = image
- isHidden = false
- }
- }
- override init(image: UIImage? = nil) {
- super.init(image: image)
- isHidden = true
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- @objc(VLCActionSheetCell)
- class ActionSheetCell: UICollectionViewCell {
- @objc static var identifier: String {
- return String(describing: self)
- }
- override var isSelected: Bool {
- didSet {
- updateColors()
- checkmark.isHidden = !isSelected
- }
- }
- let icon: ActionSheetCellImageView = {
- let icon = ActionSheetCellImageView()
- icon.translatesAutoresizingMaskIntoConstraints = false
- icon.contentMode = .scaleAspectFit
- return icon
- }()
- let name: UILabel = {
- let name = UILabel()
- name.textColor = PresentationTheme.current.colors.cellTextColor
- name.font = UIFont.systemFont(ofSize: 15)
- name.translatesAutoresizingMaskIntoConstraints = false
- name.setContentHuggingPriority(.defaultLow, for: .horizontal)
- return name
- }()
- let checkmark: UILabel = {
- let checkmark = UILabel()
- checkmark.text = "✓"
- checkmark.font = UIFont.systemFont(ofSize: 18)
- checkmark.textColor = PresentationTheme.current.colors.orangeUI
- checkmark.translatesAutoresizingMaskIntoConstraints = false
- checkmark.isHidden = true
- return checkmark
- }()
- let stackView: UIStackView = {
- let stackView = UIStackView()
- stackView.spacing = 15.0
- stackView.axis = .horizontal
- stackView.alignment = .center
- stackView.translatesAutoresizingMaskIntoConstraints = false
- return stackView
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupViews()
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- setupViews()
- }
- private func updateColors() {
- let colors = PresentationTheme.current.colors
- name.textColor = isSelected ? colors.orangeUI : colors.cellTextColor
- tintColor = isSelected ? colors.orangeUI : colors.cellDetailTextColor
- }
- override func prepareForReuse() {
- super.prepareForReuse()
- updateColors()
- }
- private func setupViews() {
- backgroundColor = PresentationTheme.current.colors.background
- stackView.addArrangedSubview(icon)
- stackView.addArrangedSubview(name)
- stackView.addArrangedSubview(checkmark)
- addSubview(stackView)
- var guide: LayoutAnchorContainer = self
- if #available(iOS 11.0, *) {
- guide = safeAreaLayoutGuide
- }
- NSLayoutConstraint.activate([
- icon.heightAnchor.constraint(equalToConstant: 25),
- icon.widthAnchor.constraint(equalTo: icon.heightAnchor),
- stackView.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
- stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
- stackView.heightAnchor.constraint(equalTo: heightAnchor),
- stackView.topAnchor.constraint(equalTo: topAnchor)
- ])
- }
- }
|