MessageOneCollectionViewCell.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // MessageOneCollectionViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/4/24.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. class MessageOneCollectionViewCell: UICollectionViewCell {
  10. class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> MessageOneCollectionViewCell {
  11. let ID = "MessageOneCollectionViewCell"
  12. collectionView.register(MessageOneCollectionViewCell.self, forCellWithReuseIdentifier: ID)
  13. let cell : MessageOneCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! MessageOneCollectionViewCell
  14. cell.indexPath = indexPath
  15. return cell
  16. }
  17. //MARK: - indexPath
  18. var indexPath: IndexPath?{
  19. didSet {
  20. }
  21. }
  22. //MARK: - 初始化
  23. override init(frame: CGRect) {
  24. super.init(frame: frame)
  25. setupViews()
  26. setupLayouts()
  27. }
  28. required init?(coder aDecoder: NSCoder) {
  29. fatalError("init(coder:) has not been implemented")
  30. }
  31. //MARK: - 设置view
  32. private func setupViews() {
  33. backgroundColor = .white
  34. addSubview(iconButton)
  35. }
  36. private func setupLayouts() {
  37. iconButton.snp.makeConstraints { (make) in
  38. make.top.equalTo(22)
  39. make.centerX.equalToSuperview()
  40. make.width.equalTo(kScreenWidth/3)
  41. make.height.equalTo(kScaleValue(value: 40)+24)
  42. }
  43. }
  44. private lazy var iconButton: UIButton = {
  45. let iconButton = UIButton(type: UIButton.ButtonType.custom)
  46. iconButton.setTitleColor(k333333Color, for: UIControl.State.normal)
  47. iconButton.titleLabel?.font = kMediumFont15
  48. iconButton.titleLabel?.adjustsFontSizeToFitWidth = true
  49. iconButton.isUserInteractionEnabled = false
  50. return iconButton
  51. }()
  52. func setCell(titles:Array<String>,images:Array<String>) {
  53. iconButton.setImage(kImage(name: images[(indexPath?.row)!]), for: UIControl.State.normal)
  54. iconButton.setTitle(titles[(indexPath?.row)!], for: UIControl.State.normal)
  55. iconButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 6)
  56. }
  57. }