-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommentTableViewCell.swift
91 lines (68 loc) · 2.25 KB
/
CommentTableViewCell.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
88
89
90
91
//
// CommentTableViewCell.swift
// CompassIO
//
// Created by LogicAppSourceIO on 06/02/17.
// Copyright © 2017 LogicAppSourceIO. All rights reserved.
//
import UIKit
class CommentTableViewCell: UITableViewCell {
// MARK: - Public API
var comment: Comment! {
didSet{
updateUI()
}
}
@IBOutlet weak var userNameLabel: UILabel!
@IBOutlet weak var commentTextLabel: UILabel!
@IBOutlet weak var likeButton: UIButton! //Deisgnable bnt
// MARK: - Private
private var currentUserDidLike: Bool = false
private func updateUI () {
userNameLabel?.text = comment.user.fullName
commentTextLabel?.text = comment.commentText
likeButton.setTitle("👻 \(comment.numberOfLikes) Likes", for: .normal)
configureButtonAppearance()
}
//Spring or designable button errror with weak . ->
private func configureButtonAppearance () {
/*
likeButton.cornerRadius = 3.0
likeButton.borderWidth = 2.0
likeButton.borderColor = UIColor.lightGrayColor()
*/
}
//Designable btn
@IBAction func likeButtonClicked(_ sender: UIButton) {
comment.userDidLike = !comment.userDidLike
if (comment.userDidLike) {
comment.numberOfLikes += 1
}else {
comment.numberOfLikes -= 1
}
self.likeButton.setTitle("👻 \(comment.numberOfLikes) Likes", for: .normal)
currentUserDidLike = comment.userDidLike
changeLikeButtonColor()
/*
//Animation
sender.animation = "pop"
sender.curve = "spring"
sender.duration = 1.6
sender.damping = 0.1
sender.velocity = 0.2
sender.animate()
*/
}
//UI BUTTON - change to designable
private func changeLikeButtonColor() {
/*
if currentUserDidLike {
likeButton.borderColor = UIColor.redColor()
likeButton.tintColor = UIColor.redColor()
} else {
likeButton.borderColor = UIColor.lightGrayColor()
likeButton.tintColor = UIColor.lightGrayColor()
}
*/
}
}