Commit 26efa1fb authored by Steven杜宇's avatar Steven杜宇

// 视频底部收藏点赞

parent d484ed9a
...@@ -47,9 +47,9 @@ class YHHomeWebBottomButton: UIButton { ...@@ -47,9 +47,9 @@ class YHHomeWebBottomButton: UIButton {
} }
} }
func setContent(_ image: String, _ title: String) { func setContent(_ image: UIImage?, _ title: String) {
bottomTitleLabel.text = title bottomTitleLabel.text = title
topImageView.image = UIImage(named: image) topImageView.image = image
} }
/* /*
// Only override draw() if you perform custom drawing. // Only override draw() if you perform custom drawing.
......
...@@ -8,7 +8,15 @@ ...@@ -8,7 +8,15 @@
import UIKit import UIKit
enum YHTintColorMode {
case light
case dark
}
class YHHomeWebBottomView: UIView { class YHHomeWebBottomView: UIView {
static let height = 59.0
typealias Block = (Bool) -> () typealias Block = (Bool) -> ()
var likeBlock: Block? var likeBlock: Block?
var starBlock: Block? var starBlock: Block?
...@@ -18,27 +26,55 @@ class YHHomeWebBottomView: UIView { ...@@ -18,27 +26,55 @@ class YHHomeWebBottomView: UIView {
var starCount: Int = 0 var starCount: Int = 0
var isStar: Bool = false { var isStar: Bool = false {
didSet { didSet {
var imgName = "home_web_star"
if isStar { if isStar {
starButton.setContent("home_web_stared", "\(starCount)") imgName = "home_web_stared"
} else {
starButton.setContent("home_web_star", "\(starCount)")
} }
var image = UIImage(named: imgName)
if tintMode == .dark {
starButton.bottomTitleLabel.textColor = .white
if !isStar {
image = image?.withRenderingMode(.alwaysTemplate).withTintColor(.white)
starButton.topImageView.tintColor = .white
}
}
starButton.setContent(image, "\(starCount)")
} }
}//是否收藏 }//是否收藏
var isLike: Bool = false { var isLike: Bool = false {
didSet { didSet {
var imgName = "home_web_like"
if isLike { if isLike {
likeButton.setContent("home_web_liked", "\(likeCount)") imgName = "home_web_liked"
} else { }
likeButton.setContent("home_web_like", "\(likeCount)") var image = UIImage(named: imgName)
if tintMode == .dark {
likeButton.bottomTitleLabel.textColor = .white
if !isLike {
image = image?.withRenderingMode(.alwaysTemplate).withTintColor(.white)
likeButton.topImageView.tintColor = .white
} }
} }
likeButton.setContent(image, "\(likeCount)")
}
}//是否点赞 }//是否点赞
var tintMode: YHTintColorMode = .light {
didSet {
if tintMode == .light {
self.backgroundColor = .white
} else if tintMode == .dark {
self.backgroundColor = .black
}
}
}
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
backgroundColor = .white tintMode = .light
setUpView() setUpView()
} }
...@@ -50,7 +86,7 @@ class YHHomeWebBottomView: UIView { ...@@ -50,7 +86,7 @@ class YHHomeWebBottomView: UIView {
likeButton = { likeButton = {
let button = YHHomeWebBottomButton() let button = YHHomeWebBottomButton()
button.setContent("home_web_like", "0") button.setContent(UIImage(named:"home_web_like"), "0")
button.addTarget(self, action: #selector(likeBtnClick), for: .touchUpInside) button.addTarget(self, action: #selector(likeBtnClick), for: .touchUpInside)
return button return button
}() }()
...@@ -64,7 +100,7 @@ class YHHomeWebBottomView: UIView { ...@@ -64,7 +100,7 @@ class YHHomeWebBottomView: UIView {
starButton = { starButton = {
let button = YHHomeWebBottomButton() let button = YHHomeWebBottomButton()
button.setContent("home_web_star", "0") button.setContent(UIImage(named:"home_web_star"), "0")
button.addTarget(self, action: #selector(starBtnClick), for: .touchUpInside) button.addTarget(self, action: #selector(starBtnClick), for: .touchUpInside)
return button return button
}() }()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment