1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // UIImageView+Virgil.swift
- // DragonflySchool
- //
- // Created by virgil on 16/2/20.
- // Copyright © 2016年 virgil. All rights reserved.
- //
- import UIKit
- extension UIImageView {
- /**
- 设置图片
-
- :param: name <#name description#>
- */
- func setImageForImageName(name: String) {
- self.image = UIImage(named: name)
- }
- // func loadImage(imgUrl:String,defaultImage:String,completedBlock:@escaping SDExternalCompletionBlock)
- // {
- // if(imgUrl != "")
- // {
- // let url = URL(string:imgUrl)
- // if(url != nil)
- // {
- // self.sd_setImage(with: url!, for: .normal) { (img, error, cacheType, url) in
- // completedBlock(img,error,cacheType,url);
- // }
- // //self.sd_setImage(with: url!, for: .normal, placeholderImage: UIImage(named: defaultImage) )
- //
- // }
- // else
- // {
- // self.setImage(UIImage(named: defaultImage), for: .normal)
- // }
- // }
- // else
- // {
- // self.setImage(UIImage(named: defaultImage), for: .normal)
- // }
- //
- // }
- func loadImage(imgUrl: String, defaultImage: String) {
- if imgUrl != "" {
- let url = URL(string: imgUrl)
- if url != nil {
- self.sd_setImage(with: url! as URL, placeholderImage: UIImage(named: defaultImage))
- } else {
- self.image = UIImage(named: defaultImage)
- }
- } else {
- self.image = UIImage(named: defaultImage)
- }
- }
- open func sd_setImage_virgil(with url: URL!, placeholderImage placeholder: UIImage!, completed completedBlock: SDExternalCompletionBlock!) {
- //[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
- self.sd_setImage(with: url, placeholderImage: placeholder, options: .retryFailed, progress: nil, completed: completedBlock)
- }
- }
|