@@ -26,7 +26,7 @@ import FlexLayoutYogaKit
26
26
label.flex.margin(10)
27
27
```
28
28
*/
29
- public final class Flex {
29
+ public final class Flex < Base : UIView > {
30
30
31
31
//
32
32
// MARK: Properties
@@ -35,20 +35,22 @@ public final class Flex {
35
35
/**
36
36
Flex items's UIView.
37
37
*/
38
- public private( set) weak var view : UIView ?
38
+ public private( set) weak var base : Base ?
39
39
private let yoga : YGLayout
40
40
41
+ public var view : UIView ? { base }
42
+
41
43
/**
42
44
Item natural size, considering only properties of the view itself. Independent of the item frame.
43
45
*/
44
46
public var intrinsicSize : CGSize {
45
47
return yoga. intrinsicSize
46
48
}
47
49
48
- init ( view : UIView ) {
49
- self . view = view
50
- self . yoga = view . yoga
51
-
50
+ init ( _ base : Base ) {
51
+ self . base = base
52
+ self . yoga = base . yoga
53
+
52
54
// Enable flexbox and overwrite Yoga default values.
53
55
yoga. isEnabled = true
54
56
}
@@ -66,7 +68,7 @@ public final class Flex {
66
68
- Returns: The flex interface corresponding to the added view.
67
69
*/
68
70
@discardableResult
69
- public func addItem( ) -> Flex {
71
+ public func addItem( ) -> Flex < UIView > {
70
72
let view = UIView ( )
71
73
return addItem ( view)
72
74
}
@@ -80,8 +82,8 @@ public final class Flex {
80
82
- Returns: The flex interface corresponding to the added view.
81
83
*/
82
84
@discardableResult
83
- public func addItem( _ view: UIView ) -> Flex {
84
- if let host = self . view {
85
+ public func addItem< Item : UIView > ( _ view: Item ) -> Flex < Item > {
86
+ if let host = base {
85
87
host. addSubview ( view)
86
88
return view. flex
87
89
} else {
@@ -1278,7 +1280,7 @@ public final class Flex {
1278
1280
*/
1279
1281
@discardableResult
1280
1282
public func backgroundColor( _ color: UIColor ) -> Flex {
1281
- if let host = self . view {
1283
+ if let host = base {
1282
1284
host. backgroundColor = color
1283
1285
return self
1284
1286
} else {
@@ -1295,7 +1297,7 @@ public final class Flex {
1295
1297
*/
1296
1298
@discardableResult
1297
1299
public func cornerRadius( _ value: CGFloat ) -> Flex {
1298
- if let host = self . view {
1300
+ if let host = base {
1299
1301
host. layer. cornerRadius = value
1300
1302
return self
1301
1303
} else {
@@ -1313,7 +1315,7 @@ public final class Flex {
1313
1315
*/
1314
1316
@discardableResult
1315
1317
public func border( _ width: CGFloat , _ color: UIColor ) -> Flex {
1316
- if let host = self . view {
1318
+ if let host = base {
1317
1319
host. layer. borderWidth = width
1318
1320
host. layer. borderColor = color. cgColor
1319
1321
return self
0 commit comments