Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yume190/kpdemo
Using KeyPath to create demo with tableview
https://github.com/yume190/kpdemo
Last synced: 11 days ago
JSON representation
Using KeyPath to create demo with tableview
- Host: GitHub
- URL: https://github.com/yume190/kpdemo
- Owner: yume190
- License: mit
- Created: 2019-05-22T02:09:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-04T01:06:53.000Z (over 4 years ago)
- Last Synced: 2024-12-18T15:02:27.266Z (about 1 month ago)
- Language: Swift
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# KPDemo
運用 `KeyPath` 快速建立你的 Demo
---
## 安裝方式
``` ruby
pod 'KPDemo', :git => 'https://github.com/yume190/KPDemo', :tag => '0.0.4'
```---
## [Demo APP](https://github.com/yume190/AdvanceAnimationDemo)
---
## 支援型態(預設 Cell)
`KPDemo` 會事先註冊下列 Cell,並依照 `KeyPath.Value` 查表,如果無符合項目,將會以 `DemoBasicCell` 呈現。
|`Cell`|`Type`|Extra Info|
|:-----|:-----|:---------|
|`DemoBoolCell`|`Bool`||
|`DemoCGRectCell`|`CGRect`|`Limit`|
|`DemoCGPointCell`|`CGPoint`|`Limit`|
|`DemoCGSizeCell`|`CGSize`|`Limit`|
|`DemoUIColorCell`|`UIColor`
`CGColor`||
|`DemoPrimtiveCell`|`Int, Int8, Int16, Int32, Int64`
`Float, Float32, Float64, Double, CGFloat`|`Limit`|``` swift
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`
``` swift
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`
``` swift
struct Yume: OptionSet {
let rawValue: Intstatic let nightmare = Yume(rawValue: 1)
static let special = Yume(rawValue: 2)
static let special2 = Yume(rawValue: 4)
}
DemoItem(
keyPath: \UIView.yume,
cell: DemoOptionSetCell.self,
info: .other([
(Yume.nightmare, "nightmare"),
(Yume.special, "special"),
])
,
```----
### CaseIterable for `DemoEnumCell`
``` swift
enum Dream: CaseIterable {
case a1
case a2
case a3
}
DemoItem(keyPath: \UIView.dream, cell: DemoEnumCell.self)
```---
## 指定 Cell
``` swift
DemoItem(keyPath: \UIView.dream, cell: DemoEnumCell.self)
```---
## 註冊 Cell 為預設 Cell
``` swift
class YourCell: UITableViewCell, DemoCellShowable, DemoCellRegistable {
var getter: (() -> Any?)? = nil
var setter: ((Any?) -> Void)? = nil
func show(showable: DemoShowable, item: Demo) {}
public static var registTypes: [Any.Type] {
return [A.self, B.self]
}
}DemoConfig.register(cell: YourCell.self)
```