1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import UIKit
- class LLCycleScrollViewCell: UICollectionViewCell {
-
- var title: String = "" {
- didSet {
- titleLabel.text = "\(title)"
- if title.count > 0 {
- titleBackView.isHidden = false
- titleLabel.isHidden = false
- } else {
- titleBackView.isHidden = true
- titleLabel.isHidden = true
- }
- }
- }
-
- var titleLabelTextColor: UIColor = UIColor.white {
- didSet {
- titleLabel.textColor = titleLabelTextColor
- }
- }
-
- var titleBackViewBackgroundColor: UIColor = UIColor.black.withAlphaComponent(0.3) {
- didSet {
- titleLabel.backgroundColor = titleBackViewBackgroundColor
- }
- }
- var titleBackView: UIView!
-
- var titleLabelHeight: CGFloat! = 56
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupImageView()
- setupLabelBackView()
- setupTitleLabel()
- }
-
- var imageView: UIImageView!
- fileprivate var titleLabel: UILabel!
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- fileprivate func setupImageView() {
- imageView = UIImageView.init()
-
- imageView.contentMode = .scaleAspectFill
- imageView.clipsToBounds = true
- self.contentView.addSubview(imageView)
- }
-
- fileprivate func setupLabelBackView() {
- titleBackView = UIView.init()
- titleBackView.backgroundColor = titleBackViewBackgroundColor
- self.contentView.addSubview(titleBackView)
- }
-
- fileprivate func setupTitleLabel() {
- titleLabel = UILabel.init()
- titleLabel.isHidden = true
- titleLabel.textColor = titleLabelTextColor
- titleLabel.numberOfLines = 2
- titleLabel.font = UIFont.systemFont(ofSize: 15)
- titleLabel.backgroundColor = UIColor.clear
- titleBackView.addSubview(titleLabel)
- }
-
- override func layoutSubviews() {
- super.layoutSubviews()
- imageView.frame = self.bounds
- titleBackView.frame = CGRect.init(x: 0, y: self.ll_h - titleLabelHeight, width: self.ll_w, height: titleLabelHeight)
- titleLabel.frame = CGRect.init(x: 15, y: 0, width: self.ll_w - 20, height: titleLabelHeight)
- }
- }
|