forked from amirdew/CollectionViewPagingLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseShapeCollectionViewCell.swift
More file actions
71 lines (54 loc) · 1.8 KB
/
BaseShapeCollectionViewCell.swift
File metadata and controls
71 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// BaseShapeCollectionViewCell.swift
// CollectionViewPagingLayout
//
// Created by Amir on 15/02/2020.
// Copyright © 2020 Amir Khorsandi. All rights reserved.
//
import UIKit
class BaseShapeCollectionViewCell: UICollectionViewCell {
// MARK: Properties
var viewModel: ShapeCardViewModel? {
didSet {
updateViews()
}
}
private(set) var shapeCardView: ShapeCardView!
private var edgeConstraints: [NSLayoutConstraint]?
// MARK: Lifecycle
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupViews()
}
override func layoutSubviews() {
super.layoutSubviews()
guard let edgeConstraints = edgeConstraints else {
return
}
let leftRightMargin = frame.width * 0.18
let topBottomMargin = frame.height * 0.06
edgeConstraints[0].constant = leftRightMargin
edgeConstraints[2].constant = -leftRightMargin
edgeConstraints[1].constant = topBottomMargin
edgeConstraints[3].constant = -topBottomMargin
}
// MARK: Private functions
private func setupViews() {
shapeCardView = ShapeCardView.instantiate()
let leftRightMargin = frame.width * 0.18
let topBottomMargin = frame.height * 0.06
edgeConstraints = contentView.fill(
with: shapeCardView,
edges: UIEdgeInsets(top: topBottomMargin, left: leftRightMargin, bottom: -topBottomMargin, right: -leftRightMargin)
)
clipsToBounds = false
contentView.clipsToBounds = false
}
private func updateViews() {
shapeCardView.viewModel = viewModel
}
}