123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- //
- // ShopViewShopInfoTableViewCell.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/5/12.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import RxSwift
- import Kingfisher
- class ShopViewShopInfoTableViewCell: UITableViewCell {
-
- let disposeBag = DisposeBag()
-
- typealias LookButtonClosure = (_ isSelected: Bool) -> Void
- var lookButtonClosure : LookButtonClosure?
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ShopViewShopInfoTableViewCell {
- let ID = "ShopViewShopInfoTableViewCell"
- tableView.register(ShopViewShopInfoTableViewCell.self, forCellReuseIdentifier: ID)
- let cell : ShopViewShopInfoTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! ShopViewShopInfoTableViewCell
- cell.indexPath = indexPath
- return cell
- }
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupViews()
- setupLayouts()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- var indexPath: IndexPath? {
- didSet {
-
- }
- }
- //MRAK: - 设置View
- func setupViews() {
- self.selectionStyle = .none
- backgroundColor = kFFA42FColor
- addSubview(shopIconImageView)
- addSubview(shopNameLabel)
- addSubview(productNumberLabel)
- addSubview(descriptionLabel)
- addSubview(lookButton)
- }
-
- func setupLayouts() {
- shopIconImageView.snp.makeConstraints { (make) in
- make.top.equalTo(12)
- make.left.equalTo(14)
- make.size.equalTo(60)
- }
- shopNameLabel.snp.makeConstraints { (make) in
- make.left.equalTo(shopIconImageView.snp.right).offset(10)
- make.right.equalTo(-14)
- make.height.equalTo(14)
- make.top.equalTo(shopIconImageView).offset(11)
- }
- productNumberLabel.snp.makeConstraints { (make) in
- make.left.equalTo(shopIconImageView.snp.right).offset(10)
- make.right.equalTo(-14)
- make.height.equalTo(14)
- make.bottom.equalTo(shopIconImageView).offset(-11)
- }
- descriptionLabel.snp.remakeConstraints { (make) in
- make.top.equalTo(shopIconImageView.snp.bottom).offset(10)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.bottom.equalTo(-35)
- }
- lookButton.snp.makeConstraints { (make) in
- make.top.equalTo(descriptionLabel.snp.bottom).offset(10)
- make.right.equalTo(-18)
- make.bottom.equalTo(-10)
- }
- }
-
- lazy var shopIconImageView: UIImageView = {
- let shopIconImageView = UIImageView()
- shopIconImageView.image = kImage(name: "default_pic")
- shopIconImageView.cornerRadius = 30
- shopIconImageView.masksToBounds = true
- return shopIconImageView
- }()
-
- lazy var shopNameLabel: UILabel = {
- let shopNameLabel = UILabel()
- shopNameLabel.text = "彩虹星球专营店"
- shopNameLabel.textColor = UIColor.white
- shopNameLabel.font = kMediumFont15
- return shopNameLabel
- }()
-
- lazy var productNumberLabel: UILabel = {
- let productNumberLabel = UILabel()
- productNumberLabel.text = "全部商品:200"
- productNumberLabel.textColor = UIColor.white
- productNumberLabel.font = kRegularFont14
- return productNumberLabel
- }()
-
- lazy var descriptionLabel: UILabel = {
- let descriptionLabel = UILabel()
- descriptionLabel.textColor = UIColor.white
- descriptionLabel.font = kRegularFont14
- descriptionLabel.numberOfLines = 0
- descriptionLabel.sizeToFit()
- return descriptionLabel
- }()
-
- lazy var lookButton: UIButton = {
- let lookButton = UIButton(type: UIButton.ButtonType.custom)
- lookButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
- lookButton.titleLabel?.font = kRegularFont14
- lookButton.isHidden = true
- lookButton.rx.tap.subscribe(onNext: { [weak self] (data) in
- lookButton.isSelected = !lookButton.isSelected
- if let lookButtonClosure = self?.lookButtonClosure {
- lookButtonClosure(lookButton.isSelected)
- }
- }).disposed(by: disposeBag)
- return lookButton
- }()
-
- var shopModel : ShopModel? {
- didSet {
-
- let str = shopModel?.shopDesc
- let attributeString = NSMutableAttributedString(string:str ?? "")
- attributeString.changeAllLineSpacing(2)
- descriptionLabel.attributedText = attributeString
-
-
- let dict = [
- NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
- ]
- let height: CGFloat = str?.boundingRect(with: CGSize(width: kScreenWidth-60-28-10, height:CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: dict, context: nil).size.height ?? 0
- let labelHeight = height
-
- let count = Int((labelHeight) / descriptionLabel.font.lineHeight)
-
- if (shopModel?.isOpen ?? false) {
- descriptionLabel.numberOfLines = 0
- descriptionLabel.lineBreakMode = .byCharWrapping
- lookButton.isSelected = true
- lookButton.setImage(UIImage.init(named: "common_word_packup"), for: UIControl.State.selected)
- lookButton.setTitle("收起", for: UIControl.State.normal)
- } else {
- descriptionLabel.numberOfLines = 2
- descriptionLabel.lineBreakMode = .byTruncatingTail
- lookButton.isSelected = false
- lookButton.setImage(kImage(name: "common_word_unfold"), for: UIControl.State.normal)
- lookButton.setTitle("查看更多", for: UIControl.State.normal)
- }
- lookButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.right, imageTitleSpace: 4)
-
- shopIconImageView.kf.setImage(with: kURLImage(name: shopModel?.logoImg ?? "default_pic"), placeholder: kImage(name: "default_pic"))
- KingfisherManager.shared.cache.clearMemoryCache()
- shopNameLabel.text = shopModel?.shopName
-
- if count > 2 {
- descriptionLabel.snp.remakeConstraints { (make) in
- make.top.equalTo(shopIconImageView.snp.bottom).offset(10)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.bottom.equalTo(-35)
- }
- lookButton.isHidden = false
- }else {
- descriptionLabel.snp.remakeConstraints { (make) in
- make.top.equalTo(shopIconImageView.snp.bottom).offset(10)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.bottom.equalTo(-10)
- }
- lookButton.isHidden = true
- }
-
- }
- }
-
- var paginationModel: PaginationModel? {
- didSet{
- productNumberLabel.text = "全部商品:\(paginationModel?.total ?? 0)"
- }
- }
- }
|