UIImageView+Virgil.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // UIImageView+Virgil.swift
  3. // DragonflySchool
  4. //
  5. // Created by virgil on 16/2/20.
  6. // Copyright © 2016年 virgil. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIImageView {
  10. /**
  11. 设置图片
  12. :param: name <#name description#>
  13. */
  14. func setImageForImageName(name: String) {
  15. self.image = UIImage(named: name)
  16. }
  17. // func loadImage(imgUrl:String,defaultImage:String,completedBlock:@escaping SDExternalCompletionBlock)
  18. // {
  19. // if(imgUrl != "")
  20. // {
  21. // let url = URL(string:imgUrl)
  22. // if(url != nil)
  23. // {
  24. // self.sd_setImage(with: url!, for: .normal) { (img, error, cacheType, url) in
  25. // completedBlock(img,error,cacheType,url);
  26. // }
  27. // //self.sd_setImage(with: url!, for: .normal, placeholderImage: UIImage(named: defaultImage) )
  28. //
  29. // }
  30. // else
  31. // {
  32. // self.setImage(UIImage(named: defaultImage), for: .normal)
  33. // }
  34. // }
  35. // else
  36. // {
  37. // self.setImage(UIImage(named: defaultImage), for: .normal)
  38. // }
  39. //
  40. // }
  41. func loadImage(imgUrl: String, defaultImage: String) {
  42. if imgUrl != "" {
  43. let url = URL(string: imgUrl)
  44. if url != nil {
  45. self.sd_setImage(with: url! as URL, placeholderImage: UIImage(named: defaultImage))
  46. } else {
  47. self.image = UIImage(named: defaultImage)
  48. }
  49. } else {
  50. self.image = UIImage(named: defaultImage)
  51. }
  52. }
  53. open func sd_setImage_virgil(with url: URL!, placeholderImage placeholder: UIImage!, completed completedBlock: SDExternalCompletionBlock!) {
  54. //[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
  55. self.sd_setImage(with: url, placeholderImage: placeholder, options: .retryFailed, progress: nil, completed: completedBlock)
  56. }
  57. }