暫無描述

LLCycleScrollViewCell.swift 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // LLCycleScrollViewCell.swift
  3. // LLCycleScrollView
  4. //
  5. // Created by LvJianfeng on 2016/11/22.
  6. // Copyright © 2016年 LvJianfeng. All rights reserved.
  7. //
  8. import UIKit
  9. class LLCycleScrollViewCell: UICollectionViewCell {
  10. // 标题
  11. var title: String = "" {
  12. didSet {
  13. titleLabel.text = "\(title)"
  14. if title.count > 0 {
  15. titleBackView.isHidden = false
  16. titleLabel.isHidden = false
  17. } else {
  18. titleBackView.isHidden = true
  19. titleLabel.isHidden = true
  20. }
  21. }
  22. }
  23. // 标题颜色
  24. var titleLabelTextColor: UIColor = UIColor.white {
  25. didSet {
  26. titleLabel.textColor = titleLabelTextColor
  27. }
  28. }
  29. // 标题背景色
  30. var titleBackViewBackgroundColor: UIColor = UIColor.black.withAlphaComponent(0.3) {
  31. didSet {
  32. titleLabel.backgroundColor = titleBackViewBackgroundColor
  33. }
  34. }
  35. var titleBackView: UIView!
  36. // 标题Label高度
  37. var titleLabelHeight: CGFloat! = 56
  38. override init(frame: CGRect) {
  39. super.init(frame: frame)
  40. setupImageView()
  41. setupLabelBackView()
  42. setupTitleLabel()
  43. }
  44. // 图片
  45. var imageView: UIImageView!
  46. fileprivate var titleLabel: UILabel!
  47. required init?(coder aDecoder: NSCoder) {
  48. fatalError("init(coder:) has not been implemented")
  49. }
  50. // Setup ImageView
  51. fileprivate func setupImageView() {
  52. imageView = UIImageView.init()
  53. // 默认模式
  54. imageView.contentMode = .scaleAspectFill
  55. imageView.clipsToBounds = true
  56. self.contentView.addSubview(imageView)
  57. }
  58. // Setup Label BackView
  59. fileprivate func setupLabelBackView() {
  60. titleBackView = UIView.init()
  61. titleBackView.backgroundColor = titleBackViewBackgroundColor
  62. self.contentView.addSubview(titleBackView)
  63. }
  64. // Setup Title
  65. fileprivate func setupTitleLabel() {
  66. titleLabel = UILabel.init()
  67. titleLabel.isHidden = true
  68. titleLabel.textColor = titleLabelTextColor
  69. titleLabel.numberOfLines = 2
  70. titleLabel.font = UIFont.systemFont(ofSize: 15)
  71. titleLabel.backgroundColor = UIColor.clear
  72. titleBackView.addSubview(titleLabel)
  73. }
  74. // MARK: layoutSubviews
  75. override func layoutSubviews() {
  76. super.layoutSubviews()
  77. imageView.frame = self.bounds
  78. titleBackView.frame = CGRect.init(x: 0, y: self.ll_h - titleLabelHeight, width: self.ll_w, height: titleLabelHeight)
  79. titleLabel.frame = CGRect.init(x: 15, y: 0, width: self.ll_w - 20, height: titleLabelHeight)
  80. }
  81. }