21 lines
577 B
Swift
21 lines
577 B
Swift
//
|
|
// UIImageView+Remote.swift
|
|
// suixinkan
|
|
//
|
|
|
|
import Kingfisher
|
|
import UIKit
|
|
|
|
extension UIImageView {
|
|
/// 加载远程头像,空 URL 时显示占位背景。
|
|
func loadRemoteImage(urlString: String?, placeholderColor: UIColor = UIColor(hex: 0xEFF6FF)) {
|
|
backgroundColor = placeholderColor
|
|
let trimmed = urlString?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
|
guard let url = URL(string: trimmed), !trimmed.isEmpty else {
|
|
image = nil
|
|
return
|
|
}
|
|
kf.setImage(with: url, placeholder: nil)
|
|
}
|
|
}
|