ReuseCellConfigure 0.4.0

ReuseCellConfigure 0.4.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年12月
SwiftSwift 版本4.0
SPM支持 SPM

Taiki Suzuki 维护。



ReuseCellConfigure

Platform
Language
Version
Carthage compatible
License

无需强制转换即可配置可重用单元格!

用法

要运行示例项目,首先克隆存储库,然后从 Example 目录运行 pod install

如果您通过 pod 安装,必须编写 import ReuseCellConfigure

// LeftIconTableViewCell.swift
class LeftIconTableViewCell: UITableViewCell, ReusableViewProtocol {
    typealias RegisterType = RegisterNib
}

// ViewController.swift
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell: UITableViewCell?
    let alphabet = String(describing: UnicodeScalar("A".unicodeScalars.first!.value + UInt32(indexPath.row))!)
    switch indexPath.row % 2 {
    case 0:
        cell = tableView.dequeue(with: LeftIconTableViewCell.self) { cell in
            cell.alphabetLabel.text = alphabet
            cell.randomBackgoundColor()
        }
    case 1:
        cell = tableView.dequeue(with: RightIconTableViewCell.self) { cell in
            cell.alphabetLabel.text = alphabet
        }
    default:
        cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell")
    }
    return cell!
}
// ReusableHeaderView.swift
class LeftIconTableViewCell: UICollectionReusableView, ReusableViewProtocol {
    typealias RegisterType = RegisterClass
}

// ViewController.swift
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let reusableView: UICollectionReusableView? = nil
    switch UICollectionView.ElementKind(rawValue: kind) {
        case .Some(.Header):
            return collectionView.dequeue(with: ReusableHeaderView.self, of: .Header, for: indexPath) { view in
                view.backgroundColor = .redColor()
            }
        case .Some(.Footer):
            return collectionView.dequeue(with: ReusableHeaderView.self, of: .Footer, for: indexPath) { view in
                view.backgroundColor = .blueColor()
            }
        default:
            return reusableView
    }
}

需求

  • Xcode 9.1 或更高版本
  • iOS 8.0 或更高版本

安装

CocoaPods

ReuseCellConfigure 通过 CocoaPods 提供。安装方法如下
,只需将以下行添加到您的 Podfile 中

pod "ReuseCellConfigure"

Carthage

如果您正在使用 Carthage,只需将
ReuseCellConfigure 添加到您的 Cartfile

github "marty-suzuki/ReuseCellConfigure"

请确保将 ReuseCellConfigure.framework 添加到“已链接框架和库”以及“copy-frameworks”构建阶段。

作者

Taiki Suzuki, [email protected]

许可证

ReuseCellConfigure 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。