-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAboutShotTableViewCell.swift
87 lines (62 loc) · 2.27 KB
/
AboutShotTableViewCell.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// AboutShotTableViewCell.swift
// Swish
//
// Created by Andrew Ervin Gierke on 4/21/17.
// Copyright © 2017 And. All rights reserved.
//
import UIKit
protocol AboutShotCellDelegate {
func shareButtonTapped(_ sender: AboutShotTableViewCell)
func userButtonTapped(_ sender: AboutShotTableViewCell)
}
class AboutShotTableViewCell: UITableViewCell {
//MARK: - Properties
var delegate: AboutShotCellDelegate?
var shot: Shot? {
didSet {
updateViews()
}
}
//MARK: - Outlets
@IBOutlet weak var userNameLabel: UILabel!
@IBOutlet weak var userAvatarImageView: UIImageView!
@IBOutlet weak var likeCountLabel: UILabel!
@IBOutlet weak var viewCountLabel: UILabel!
@IBOutlet weak var shareButton: UIButton!
//MARK: - Actions
@IBAction func ShareButtonTapped(_ sender: Any) {
delegate?.shareButtonTapped(self)
}
@IBAction func userButtonTapped(_ sender: Any) {
delegate?.userButtonTapped(self)
}
//MARK: - View lifecycle
override func awakeFromNib() {
super.awakeFromNib()
backgroundColor = Colors.backgroundGray
}
//MARK: - Helpers
func updateViews() {
guard let shot = shot, let user = shot.user else { return }
userNameLabel.text = "by \(user.userUserName)"
likeCountLabel.text = "\(shot.likeCount)"
viewCountLabel.text = "\(shot.viewCount)"
if user.userAvatar != nil {
self.userAvatarImageView.image = user.userAvatar
} else {
ImageController.image(forURL: user.userAvatarURL) { (image) in
DispatchQueue.main.async {
self.userAvatarImageView.image = image
}
}
}
shareButton.backgroundColor = .clear
userNameLabel.font = UIFont(name: "ArialRoundedMTBold", size: 18)
viewCountLabel.textColor = Colors.dribbbleDarkGray
likeCountLabel.textColor = Colors.dribbbleDarkGray
userNameLabel.textColor = Colors.primaryPink
userAvatarImageView.layer.cornerRadius = userAvatarImageView.frame.size.width/2
userAvatarImageView.clipsToBounds = true
}
}