12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // UIButton+Virgil.swift
- // DragonflySchool
- //
- // Created by virgil on 16/2/20.
- // Copyright © 2016年 virgil. All rights reserved.
- //
- import UIKit
- extension UIButton {
- func loadImage(imgUrl: String, defaultImage: String) {
- if imgUrl != "" {
- let url = URL(string: imgUrl)
- if url != nil {
- 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, 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 loadBackgroudImage(imgUrl: String, defaultImage: String) {
- if imgUrl != "" {
- let url = URL(string: imgUrl)
- if url != nil {
- self.sd_setBackgroundImage(with: url!, for: .normal, placeholderImage: UIImage(named: defaultImage) )
- } else {
- self.setBackgroudImage(name: defaultImage)
- }
- } else {
- self.setBackgroudImage(name: defaultImage)
- }
- }
- }
|