|
@@ -0,0 +1,218 @@
|
|
|
+//
|
|
|
+// RecommendDetailContentCell.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by Christopher on 2019/6/13.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+// 推荐图文内容--图文Cell
|
|
|
+
|
|
|
+import UIKit
|
|
|
+
|
|
|
+class RecommendDetailContentCell: UITableViewCell {
|
|
|
+
|
|
|
+ class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RecommendDetailContentCell {
|
|
|
+ let ID = "RecommendDetailContentCell"
|
|
|
+ tableView.register(RecommendDetailContentCell.self, forCellReuseIdentifier: ID)
|
|
|
+ let cell : RecommendDetailContentCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! RecommendDetailContentCell
|
|
|
+ cell.indexPath = indexPath
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
+ super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+
|
|
|
+// collectionView.reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ var indexPath: IndexPath? {
|
|
|
+ didSet {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //MRAK: - 设置View
|
|
|
+ private func setupViews() {
|
|
|
+ self.selectionStyle = .none
|
|
|
+ backgroundColor = kffffffColor
|
|
|
+
|
|
|
+ addSubview(titleLabel)
|
|
|
+ addSubview(rainbowBeanView)
|
|
|
+ rainbowBeanView.addSubview(beanImageView)
|
|
|
+ rainbowBeanView.addSubview(beanLabel)
|
|
|
+ addSubview(contentLabel)
|
|
|
+ addSubview(collectionView)
|
|
|
+ addSubview(timeLabel)
|
|
|
+ addSubview(readLabel)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupLayouts() {
|
|
|
+ titleLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(20)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ }
|
|
|
+ rainbowBeanView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(titleLabel.snp_bottom).offset(10)
|
|
|
+ make.left.equalTo(titleLabel.snp_left)
|
|
|
+ make.height.equalTo(24)
|
|
|
+ }
|
|
|
+ beanImageView.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(10)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.size.equalTo(19)
|
|
|
+ }
|
|
|
+ beanLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(beanImageView.snp_right).offset(5)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.height.equalTo(19)
|
|
|
+ make.right.equalToSuperview().offset(-10)
|
|
|
+ }
|
|
|
+ contentLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(rainbowBeanView.snp_bottom).offset(10)
|
|
|
+ make.left.equalTo(titleLabel.snp_left)
|
|
|
+ make.right.equalTo(titleLabel.snp_right)
|
|
|
+ }
|
|
|
+ collectionView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(contentLabel.snp_bottom).offset(15)
|
|
|
+ make.left.equalTo(titleLabel.snp_left)
|
|
|
+ make.right.equalTo(titleLabel.snp_right)
|
|
|
+ }
|
|
|
+ timeLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(collectionView.snp_bottom).offset(15)
|
|
|
+ make.left.equalTo(titleLabel.snp_left)
|
|
|
+ make.height.equalTo(15)
|
|
|
+ make.bottom.equalToSuperview().offset(-20)
|
|
|
+ }
|
|
|
+ readLabel.snp.makeConstraints { (make) in
|
|
|
+ make.right.equalTo(titleLabel.snp_right)
|
|
|
+ make.centerY.equalTo(timeLabel.snp_centerY)
|
|
|
+ make.height.equalTo(15)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = "绿皮书是一本历史上真实存在的黑人出行指南?是的,真是存在"
|
|
|
+ titleLabel.textColor = k262626Color
|
|
|
+ titleLabel.font = kMediumFont16
|
|
|
+ titleLabel.textAlignment = .left
|
|
|
+ titleLabel.numberOfLines = 0
|
|
|
+ return titleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var rainbowBeanView: UIView = {
|
|
|
+ let rainbowBeanView = UIView()
|
|
|
+ rainbowBeanView.backgroundColor = kfff8ecColor
|
|
|
+ rainbowBeanView.cornerRadius = 12
|
|
|
+ rainbowBeanView.masksToBounds = true
|
|
|
+ return rainbowBeanView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var beanImageView : UIImageView = {
|
|
|
+ let beanImageView = UIImageView()
|
|
|
+ beanImageView.image = kImage(name: "page05")
|
|
|
+ return beanImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var beanLabel: UILabel = {
|
|
|
+ let beanLabel = UILabel()
|
|
|
+ beanLabel.text = "666彩虹豆待收获"
|
|
|
+ beanLabel.textColor = kFFA42FColor
|
|
|
+ beanLabel.font = kRegularFont13
|
|
|
+ beanLabel.textAlignment = .left
|
|
|
+ return beanLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var contentLabel: UILabel = {
|
|
|
+ let contentLabel = UILabel()
|
|
|
+ contentLabel.text = "The four-time Tour de France winner crashed at high-speed on Wednesday fracturing his right elbow, and right femur as well as several ribs. The fall took place during a recon of the stage 4 time trial at the Criterium du Dauphine and after several hours of medical assistance on the roadside near Roanne Froome was airlifted to hospital."
|
|
|
+ contentLabel.textColor = k313334Color
|
|
|
+ contentLabel.font = kRegularFont15
|
|
|
+ contentLabel.textAlignment = .left
|
|
|
+ contentLabel.numberOfLines = 0
|
|
|
+ return contentLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var timeLabel: UILabel = {
|
|
|
+ let timeLabel = UILabel()
|
|
|
+ timeLabel.text = "6个小时前"
|
|
|
+ timeLabel.textColor = kbbbbbbColor
|
|
|
+ timeLabel.font = kRegularFont12
|
|
|
+ timeLabel.textAlignment = .left
|
|
|
+ return timeLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var readLabel: UILabel = {
|
|
|
+ let readLabel = UILabel()
|
|
|
+ readLabel.text = "6个小时前"
|
|
|
+ readLabel.textColor = kbbbbbbColor
|
|
|
+ readLabel.font = kRegularFont12
|
|
|
+ readLabel.textAlignment = .right
|
|
|
+ return readLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var collectionView: UICollectionView = {
|
|
|
+ let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
|
|
|
+ collectionView.backgroundColor = kffffffColor
|
|
|
+ collectionView.delegate = self;
|
|
|
+ collectionView.dataSource = self;
|
|
|
+ collectionView.showsVerticalScrollIndicator = false
|
|
|
+ collectionView.showsHorizontalScrollIndicator = false
|
|
|
+ collectionView.bounces = false
|
|
|
+ collectionView.isScrollEnabled = false
|
|
|
+ return collectionView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
|
+ let collectionViewLayout = UICollectionViewLeftAlignedLayout.init()
|
|
|
+ collectionViewLayout.minimumLineSpacing = 10
|
|
|
+ collectionViewLayout.minimumInteritemSpacing = 10
|
|
|
+// collectionViewLayout.sectionInset = UIEdgeInsets(top: 10, left: 14, bottom: 10, right: 14)
|
|
|
+ collectionViewLayout.scrollDirection = UICollectionView.ScrollDirection.vertical
|
|
|
+ collectionViewLayout.estimatedItemSize = CGSize(width: ((kScreenWidth - 28) - 3*10)/4, height: 24)
|
|
|
+ return collectionViewLayout
|
|
|
+ }()
|
|
|
+
|
|
|
+ //加载数据
|
|
|
+ func reloadData() {
|
|
|
+ //collectionView重新加载数据
|
|
|
+ self.collectionView.reloadData()
|
|
|
+ //更新collectionView的高度约束
|
|
|
+ let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
|
|
|
+ collectionView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(contentLabel.snp_bottom).offset(15)
|
|
|
+ make.left.equalTo(titleLabel.snp_left)
|
|
|
+ make.right.equalTo(titleLabel.snp_right)
|
|
|
+ make.height.equalTo(contentSize.height)
|
|
|
+ }
|
|
|
+ self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension RecommendDetailContentCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
|
+ func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
+ return 5
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
+ let cell = CommunityTagCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
+ print("点击了collection----\(indexPath.row)")
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|