-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnippetCell.swift
56 lines (49 loc) · 1.8 KB
/
SnippetCell.swift
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
//
// SnippetCell.swift
// StoryboardSnippets
//
// Created by Elliott Io on 4/25/20.
// Copyright © 2020 elliott io. All rights reserved.
//
import Foundation
import UIKit
class SnippetCell: UICollectionViewCell {
@IBOutlet weak var labelTitle: UILabel!
@IBOutlet weak var labelSubtitle: UILabel!
@IBOutlet weak var labelSourceFiles: UILabel!
@IBOutlet weak var bgImageView: UIImageView!
@IBOutlet weak var borderView: UIView!
@IBOutlet weak var blurView: UIVisualEffectView!
let cornerRadius: CGFloat = 30.0
override func awakeFromNib() {
super.awakeFromNib()
// set the border
self.bgImageView.layer.cornerRadius = self.cornerRadius
self.blurView.layer.cornerRadius = self.cornerRadius
self.blurView.layer.borderWidth = Styles.borderWidth
self.blurView.layer.borderColor = Styles.borderColor
self.blurView.clipsToBounds = true
}
func set(_ snippet: Snippet) {
self.labelTitle.text = snippet.title
self.labelSubtitle.text = snippet.subtitle
self.labelSourceFiles.text = ""
for file in snippet.sourceFiles {
self.labelSourceFiles.text?.append("\(file)\r")
}
self.blurView.alpha = 1
guard let imageName = snippet.assetImageName,
let image = UIImage(named: imageName) else {
let defaultImage = UIImage(named: "tile")!
if self.bgImageView.image != defaultImage {
self.bgImageView.image = defaultImage
}
return }
self.bgImageView.image = image
UIView.animate(withDuration: AntimationDuration.fadeInOut.rawValue, animations: {
self.blurView.alpha = 0
}, completion: { result in
// success
})
}
}