swift kingfisher 加载图片

2020/09/14 09:25
阅读数 2.6K

地址: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
        ]
         
        
        )
       
      
    }
    
    
 
}


展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部