File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77#if !os(macOS)
88import UIKit
99
10- open class CapsuleView : UIView {
10+ open class CapsuleView < T: UIView > : UIView {
11+
12+ public let contentView : T
13+
14+ public init ( contentView: T ) {
15+ self . contentView = contentView
16+ super. init ( frame: . zero)
17+ configView ( )
18+ }
19+
20+ override init ( frame: CGRect ) {
21+ self . contentView = T ( frame: frame)
22+ super. init ( frame: frame)
23+ configView ( )
24+ }
25+
26+ required public init ? ( coder: NSCoder ) {
27+ fatalError ( " init(coder:) has not been implemented " )
28+ }
29+
1130 open override func layoutSubviews( ) {
1231 super. layoutSubviews ( )
13- layer. cornerRadius = frame. height / 2
32+ layer. cornerRadius = bounds. height / 2
33+ layer. masksToBounds = true
1434 }
35+
1536}
37+
38+ extension CapsuleView : ContentViewProtocol {
39+ var containerView : UIView {
40+ return contentView
41+ }
42+ }
43+
1644#endif
Original file line number Diff line number Diff line change @@ -11,10 +11,10 @@ import UIKit
1111
1212public class ContentView < View: UIView > : UIView {
1313
14- private lazy var leftConstraint = contentView. leftAnchor . constraint ( equalTo: leftAnchor , constant: edges. left)
14+ private lazy var leftConstraint = contentView. leadingAnchor . constraint ( equalTo: leadingAnchor , constant: edges. left)
1515 private lazy var topConstraint = contentView. topAnchor. constraint ( equalTo: topAnchor, constant: edges. top)
1616 private lazy var bottomConstraint = contentView. bottomAnchor. constraint ( equalTo: bottomAnchor, constant: - edges. bottom)
17- private lazy var rightConstraint = contentView. rightAnchor . constraint ( equalTo: rightAnchor , constant: - edges. right)
17+ private lazy var rightConstraint = contentView. trailingAnchor . constraint ( equalTo: trailingAnchor , constant: - edges. right)
1818
1919 public let contentView : View
2020
@@ -43,4 +43,5 @@ public class ContentView<View: UIView>: UIView {
4343 }
4444
4545}
46+
4647#endif
Original file line number Diff line number Diff line change 1+ //
2+ // ContentViewProtocol.swift
3+ // FXViewKit
4+ //
5+ // Created by aria on 2022/7/2.
6+ //
7+
8+ import Foundation
9+
10+ protocol ContentViewProtocol {
11+ var containerView : UIView { get }
12+ }
13+
14+ extension ContentViewProtocol where Self: UIView {
15+ func configView( ) {
16+ containerView. translatesAutoresizingMaskIntoConstraints = false
17+ addSubview ( containerView)
18+ NSLayoutConstraint . activate ( [
19+ containerView. leadingAnchor. constraint ( equalTo: leadingAnchor) ,
20+ containerView. topAnchor. constraint ( equalTo: topAnchor) ,
21+ containerView. trailingAnchor. constraint ( equalTo: trailingAnchor) ,
22+ containerView. bottomAnchor. constraint ( equalTo: bottomAnchor) ,
23+ ] )
24+ }
25+ }
Original file line number Diff line number Diff line change 88#if !os(macOS)
99import UIKit
1010
11- open class GradientView : UIView {
11+ open class GradientView < T : UIView > : UIView {
1212 open override class var layerClass : AnyClass {
1313 return CAGradientLayer . classForCoder ( )
1414 }
@@ -17,17 +17,33 @@ open class GradientView: UIView {
1717 return layer as! CAGradientLayer
1818 }
1919
20+ public let contentView : T
21+
2022 public convenience init ( ) {
2123 self . init ( frame: . zero)
2224 }
2325
26+ public init ( contentView: T ) {
27+ self . contentView = contentView
28+ super. init ( frame: . zero)
29+ configView ( )
30+ }
31+
2432 public override init ( frame: CGRect ) {
33+ self . contentView = T ( )
2534 super. init ( frame: frame)
2635 isUserInteractionEnabled = false
36+ configView ( )
2737 }
2838
2939 required public init ? ( coder: NSCoder ) {
3040 fatalError ( " init(coder:) has not been implemented " )
3141 }
3242}
43+
44+ extension GradientView : ContentViewProtocol {
45+ var containerView : UIView {
46+ return contentView
47+ }
48+ }
3349#endif
You can’t perform that action at this time.
0 commit comments