KPDemo 0.0.6

KPDemo 0.0.6

yume190 维护。



KPDemo 0.0.6

KPDemo

运用 KeyPath 快速构建您的 Demo


安装方式

pod 'KPDemo', :git => 'https://github.com/yume190/KPDemo', :tag => '0.0.4'

Demo 应用


支持类型(默认 Cell)

KPDemo 中,预先注册以下 Cell,并按照 KeyPath.Value 查找表,如果没有找到匹配项,则使用 DemoBasicCell 显示。

Cell 类型 额外信息
DemoBoolCell 布尔型
DemoCGRectCell CGRect 限制
DemoCGPointCell CGPoint 限制
DemoCGSizeCell CGSize 限制
DemoUIColorCell UIColor
CGColor
DemoPrimtiveCell 整型,Int8,Int16,Int32,Int64
浮点型,Float32,Float64,Double,CGFloat
限制
DemoItem(keyPath: \UIView.layer.masksToBounds)
DemoItem(keyPath: \UIView.frame)
DemoItem(keyPath: \UIView.frame.origin)
DemoItem(keyPath: \UIView.frame.size)
DemoItem(keyPath: \UIView.frame.backgroundColor)
DemoItem(keyPath: \UIView.layer.contentsScale, demoDescription: "@1x @2x @3x", info: .limit(.value1_3)),

特殊 Cell

demoPickercell

DemoItem(
    keyPath: \UIView.layer.contentsGravity,
    cell: DemoPickerCell.self,
    info: .table([
        CALayerContentsGravity.center: "center",
        CALayerContentsGravity.top: "top",
        CALayerContentsGravity.bottom: "bottom",
        CALayerContentsGravity.left: "left",
        CALayerContentsGravity.right: "right",
        CALayerContentsGravity.topLeft: "topLeft",
        CALayerContentsGravity.topRight: "topRight",
        CALayerContentsGravity.bottomLeft: "bottomLeft",
        CALayerContentsGravity.bottomRight: "bottomRight",
        CALayerContentsGravity.resize: "resize",
        CALayerContentsGravity.resizeAspect: "resizeAspect",
        CALayerContentsGravity.resizeAspectFill: "resizeAspectFill",
    ])
)

OptionSet for demoOptionSetCell

struct Yume: OptionSet {
    let rawValue: Int

    static let nightmare = Yume(rawValue: 1)
    static let special = Yume(rawValue: 2)
    static let special2 = Yume(rawValue: 4)
}
DemoItem(
    keyPath: \UIView.yume,
    cell: DemoOptionSetCell<Yume>.self,
    info: .other([
        (Yume.nightmare, "nightmare"),
        (Yume.special, "special"),
    ])
,

CaseIterable for demoEnumCell

enum Dream: CaseIterable {
    case a1
    case a2
    case a3
}
DemoItem(keyPath: \UIView.dream, cell: DemoEnumCell<Dream>.self)

指定 Cell

DemoItem(keyPath: \UIView.dream, cell: DemoEnumCell<Dream>.self)

注册 Cell 为默认 Cell

class YourCell: UITableViewCell, DemoCellShowable, DemoCellRegistable {
    var getter: (() -> Any?)? = nil
    var setter: ((Any?) -> Void)? = nil
    func show<T>(showable: DemoShowable, item: Demo<T>) {}
    public static var registTypes: [Any.Type] {
        return [A.self, B.self]
    }
}

DemoConfig.register(cell: YourCell.self)