频道栏目
首页 > 资讯 > 其他 > 正文

swift4 tableViewCell结合Kingfisher 、SnapKit的使用分析

18-07-30        来源:[db:作者]  
收藏   我要投稿

swift4 tableViewCell结合Kingfisher 、SnapKit的使用分析

pod中加入第三方 Kingfisher  SnapKit

pod第三方

platform :ios, '10.0'

target 'ChatWorld' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  pod 'Alamofire'
  pod 'SwiftyJSON'
  pod 'HandyJSON', '~> 4.1.1'
  pod 'Kingfisher'
  pod 'SVProgressHUD'
  pod 'MJRefresh'
  pod 'SGPagingView'
  pod 'BMPlayer'
  pod 'FDFullscreenPopGesture'
  pod 'SnapKit'
  pod 'lottie-ios'
  pod 'HyphenateLite'
  pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-hyphenate-cocoapods.git'
end
 

cell的编写

import UIKit

class ConversionCell: UITableViewCell {
     //MARK: 懒加载
    lazy var iconIM:UIImageView = {
       let imageView = UIImageView.init()
       return imageView
    }()
    lazy var topLab:UILabel = {
        let lab = UILabel.init()
        return lab
    }()
    lazy var messageLab:UILabel = {
        let lab = UILabel.init()
        return lab
    }()
    lazy var dateLab:UILabel = {
        let lab = UILabel.init()
        return lab
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
       self.initUI()
    }
    func updateUI(){
        
    }

//UI布局
    func initUI(){
        self.contentView.addSubview(self.iconIM)
        self.contentView.addSubview(self.dateLab)
        self.contentView.addSubview(self.topLab)
        self.contentView.addSubview(self.messageLab)
        self.iconIM.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.centerY.equalTo(self.snp.centerY)
            make.width.height.equalTo(60)
        }
        self.dateLab.snp.makeConstraints { (make) in
            make.right.equalTo(-8)
            make.top.equalTo(5)
            make.width.equalTo(80)
            make.height.equalTo(20)
        }
        self.topLab.snp.makeConstraints { (make) in
            make.left.equalTo(iconIM.snp.right).offset(8)
            make.top.right.equalTo(0)
            make.height.equalTo(30)
        }
        self.messageLab.snp.makeConstraints { (make) in
            make.left.equalTo(self.iconIM.snp.right).offset(8)
            make.right.equalTo(-8)
            make.top.equalTo(self.snp.centerY)
            make.bottom.equalTo(-8)
        }
    
    }
    override func layoutSubviews() {
        super.layoutSubviews()
      
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

2.tableView中的使用

extension MessageViewController{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = ConversionCell.init(style: .default, reuseIdentifier: "cell")
         cell.dateLab.text = "2018-12-13"
        cell.messageLab.text = "在不?"
       cell.iconIM.kf.setImage(with: URL(string: "http://yourImage.com/id=1"), placeholder: UIImage.init(named: "4"), options:nil, progressBlock: nil, completionHandler: nil)
        cell.topLab.text = "狩猎开始"
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 80
    }  
}

Kingfisher 处理图片的​流行第三方

​​​​​cell.iconIM.kf.setImage(with: URL(string: "http://yourImage.com/id=1"), placeholder: UIImage.init(named: "4"), options:nil, progressBlock: nil, completionHandler: nil)
相关TAG标签
上一篇:关于AndroidStudio SDK Baiduyun Download (for android 6.0 development/Android Studio 1.5 - 2016)代码分析
下一篇:关于线程交替打印奇偶数的实例讲解
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站