swift kingfisher 加载图片

地址:https://github.com/onevcat/Kingfisher

platform :ios, '9.0'
use_frameworks!

target 'videowallpaper' do

  pod 'Kingfisher'
  pod 'Alamofire'
  pod 'SwiftyJSON'
  pod 'Dollar'
  pod 'SnapKit'
  pod 'Kingfisher'
end

最简单的用法,直接加载图片

//
//  ViewController.swift
//  videowallpaper
//
//  Created by liuan on 2020/6/11.
//  Copyright © 2020 liuan. All rights reserved.
//

import UIKit
import Kingfisher

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let uiLableHeight:CGFloat = 60
        let uiLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height:uiLableHeight))
        uiLabel.backgroundColor = .green
        uiLabel.text = "猴头客公众号"
        let imageViewHeight = view.bounds.height - uiLableHeight
        let imageView = UIImageView(frame: CGRect(x: 0, y: uiLableHeight, width: view.bounds.width, height: imageViewHeight))
      
        view.addSubview(uiLabel)
           view.addSubview(imageView)
        
        let url = URL(string: "https://www.houtouke.com/wp-content/uploads/2019/08/qrcode_for_gh_1dd5f06ca86b_258-1.jpg")
        
        
        imageView.kf.setImage(with: url)
        
    }
    
 
}


缓存加载图片,并设置默认图

//
//  ViewController.swift
//  videowallpaper
//
//  Created by liuan on 2020/6/11.
//  Copyright © 2020 liuan. All rights reserved.
//

import UIKit
import Kingfisher


class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let uiLableHeight:CGFloat = 60
        let uiLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height:uiLableHeight))
        uiLabel.backgroundColor = .green
        uiLabel.text = "猴头客公众号"
        let imageViewHeight = view.bounds.height - uiLableHeight
        let imageView = UIImageView(frame: CGRect(x: 0, y: uiLableHeight, width: view.bounds.width, height: imageViewHeight))
      
        view.addSubview(uiLabel)
           view.addSubview(imageView)
        
        let url = URL(string: "https://www.houtouke.com/wp-content/uploads/2019/08/qrcode_for_gh_1dd5f06ca86b_258-1.jpg")
        
        
//        imageView.kf.setImage(with: url)
   
        imageView.kf.indicatorType = .activity
        imageView.kf.setImage(
            with:url,
            placeholder: UIImage(named: "logo_80"),
            options: [
        
            .processor(RoundCornerImageProcessor(cornerRadius: 100)),
            .scaleFactor(UIScreen.main.scale),
            .cacheOriginalImage
        ]
         
        
        )
       
      
    }
    
    
 
}


swift kingfisher 加载图片_第1张图片

你可能感兴趣的:(#,swift)