@@ -18,12 +18,12 @@ class CardView: UIView {
19 var minWidth: CGFloat = 300 {
19 var minWidth: CGFloat = 300 {
21− update()
21+// update()
24 var height: CGFloat = 400 {
24 var height: CGFloat = 400 {
26− update()
26+// update()
@@ -31,17 +31,32 @@ class CardView: UIView {
31 super.init(frame: frame)
31 super.init(frame: frame)
32 layer.masksToBounds = true
32 layer.masksToBounds = true
33 layer.cornerRadius = 20
33 layer.cornerRadius = 20
34+ gradient.colors = [#colorLiteral(red: 0.9841352105, green: 0.9841352105, blue: 0.9841352105, alpha: 1).cgColor, #colorLiteral(red: 0.9456828237, green: 0.9456828237, blue: 0.9456828237, alpha: 1).cgColor]
35+ gradient.startPoint = CGPoint(x: 0.5, y: 0)
36+ gradient.endPoint = CGPoint(x: 0.5, y: 1)
37+ layer.addSublayer(gradient)
34− backgroundColor = #colorLiteral(red: 0.9638966278, green: 0.9734401588, blue: 0.9734401588, alpha: 1)
38+// backgroundColor = #colorLiteral(red: 0.9638966278, green: 0.9734401588, blue: 0.9734401588, alpha: 1)
37 required init?(coder aDecoder: NSCoder) {
41 required init?(coder aDecoder: NSCoder) {
38 fatalError("init(coder:) has not been implemented")
42 fatalError("init(coder:) has not been implemented")
45+ private let gradient = CAGradientLayer()
41 private let padding = CGPoint(x: 32, y: 32)
48 private let padding = CGPoint(x: 32, y: 32)
42 private let vPadding1: CGFloat = 16
49 private let vPadding1: CGFloat = 16
43 private let vPadding2: CGFloat = 16
50 private let vPadding2: CGFloat = 16
44− private let minTextHeight: CGFloat = 50
51+ private var minTextHeight: CGFloat {
52+ return CGFloat(height * 0.2)
54+ private let gradientRatio: CGFloat = 0.2
55+ private let minGradientAmount: CGFloat = 70
56+ private let hiddenByGradient: CGFloat = 10
57+ private var maxAttachmentDim: CGFloat {
58+ return minWidth / 2.3
46// private let avatar = UIImage()
61// private let avatar = UIImage()
47// private let name = UIImage()
62// private let name = UIImage()
@@ -54,10 +69,9 @@ class CardView: UIView {
54 addSubview(largeStack)
69 addSubview(largeStack)
56 let userView = StackView(axis: .horizontal, alignment: .center)
71 let userView = StackView(axis: .horizontal, alignment: .center)
57−// userView.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
60− let avatarDim: CGFloat = 50
74+ let avatarDim: CGFloat = 64
61 let avatar = UIImageView()
75 let avatar = UIImageView()
62 post?.owner?.avatar?.load(into: avatar)
76 post?.owner?.avatar?.load(into: avatar)
63 avatar.layer.cornerRadius = avatarDim/2
77 avatar.layer.cornerRadius = avatarDim/2
@@ -74,6 +88,7 @@ class CardView: UIView {
74 let lastName = post?.owner?.lastName ?? ""
88 let lastName = post?.owner?.lastName ?? ""
75 userName.text = "\(firstName) \(lastName)"
89 userName.text = "\(firstName) \(lastName)"
76 userName.font = UIFont.systemFont(ofSize: 28, weight: UIFontWeightHeavy)
90 userName.font = UIFont.systemFont(ofSize: 28, weight: UIFontWeightHeavy)
91+ userName.textColor = UIColor.darkText
77 userName.sizeToFit()
92 userName.sizeToFit()
78 userView.addArrangedSubview(.view(userName))
93 userView.addArrangedSubview(.view(userName))
@@ -93,7 +108,7 @@ class CardView: UIView {
93 photoView.verticalPadding = 8
108 photoView.verticalPadding = 8
94 photoView.padding = CGPoint.zero
109 photoView.padding = CGPoint.zero
95 photoView.maxWidth = width
110 photoView.maxWidth = width
96− var maxPhotoDim: CGFloat = 150
111+ var maxPhotoDim: CGFloat = maxAttachmentDim
97 if let attachments = post?.attachments {
112 if let attachments = post?.attachments {
98 for attachment in attachments {
113 for attachment in attachments {
99 if let v = attachment.value {
114 if let v = attachment.value {
@@ -103,6 +118,7 @@ class CardView: UIView {
103 var pHeight = photo.height.value >>> {CGFloat($0)} {
118 var pHeight = photo.height.value >>> {CGFloat($0)} {
104 let photoV = UIImageView()
119 let photoV = UIImageView()
105 photoV.layer.minificationFilter = kCAFilterTrilinear
120 photoV.layer.minificationFilter = kCAFilterTrilinear
121+ photoV.contentMode = .scaleAspectFill
106 photo.image?.load(into: photoV)
122 photo.image?.load(into: photoV)
107 var k: CGFloat!
123 var k: CGFloat!
108 if pWidth > pHeight {
124 if pWidth > pHeight {
@@ -125,10 +141,10 @@ class CardView: UIView {
125 photoView.layoutIfNeeded()
141 photoView.layoutIfNeeded()
127 var textHeight = height
143 var textHeight = height
128− textHeight -= padding.y + vPadding1 + userView.frame.height
144+ textHeight -= padding.y * 2 + vPadding1 + userView.frame.height
129 if let count = post?.attachments.count{
145 if let count = post?.attachments.count{
130 if count > 0 {
146 if count > 0 {
131− textHeight -= vPadding2 + photoView.frame.height + padding.y
147+ textHeight -= vPadding2 + photoView.frame.height
134 print(textHeight)
150 print(textHeight)
@@ -140,9 +156,25 @@ class CardView: UIView {
140 let bodyWidth: Double = Double(width)
156 let bodyWidth: Double = Double(width)
141 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
157 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
142 body.text = post?.body
158 body.text = post?.body
159+ body.textColor = UIColor.darkText
143 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
160 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
144− body.frame.size.height = min(size.height, textHeight)
145 body.frame.size.width = size.width
161 body.frame.size.width = size.width
162+ if size.height > textHeight {
163+ body.frame.size.height = textHeight
164+ let maskView = UIView()
165+ let maskLayer = CAGradientLayer()
166+ maskLayer.colors = [UIColor.black.cgColor, UIColor.clear.cgColor]
167+ maskLayer.endPoint = CGPoint(x: 0.5, y: 1 - (hiddenByGradient/textHeight))
168+ let minPoint = minGradientAmount / textHeight
169+ maskLayer.startPoint = CGPoint(x: 0.5, y: 1 - max(minPoint, gradientRatio))
170+ print(maskLayer.startPoint)
171+ maskLayer.frame = body.bounds
172+ maskView.frame = body.bounds
173+ maskView.layer.addSublayer(maskLayer)
174+ body.mask = maskView
176+ body.frame.size.height = size.height
147 largeStack.addArrangedSubview(.view(body))
179 largeStack.addArrangedSubview(.view(body))
@@ -157,5 +189,8 @@ class CardView: UIView {
158 frame.size = CGSize(width: width + padding.x * 2, height: min(height, largeStack.frame.height))
190 frame.size = CGSize(width: width + padding.x * 2, height: min(height, largeStack.frame.height))
192+ gradient.frame = self.bounds
193+ gradient.endPoint = CGPoint(x: 0.5, y: bounds.height / height)