Files
android
assets
ios
Flutter
Runner
Assets.xcassets
Base.lproj
NativeViews
BlurHashDecoder.swift
ImageView.swift
NativeImage.swift
AppDelegate.swift
GoogleService-Info.plist
Info.plist
Runner-Bridging-Header.h
Runner.entitlements
Runner.xcodeproj
Runner.xcworkspace
RunnerTests
.gitignore
Podfile
Podfile.lock
lib
linux
macos
web
windows
.gitignore
.metadata
README.md
analysis_options.yaml
build.yaml
devtools_options.yaml
firebase.json
pubspec.lock
pubspec.yaml
App/ios/Runner/NativeViews/ImageView.swift
2025-04-22 01:12:56 +08:00

43 lines
1.1 KiB
Swift

//
// ImageView.swift
// Runner
//
// Created by LittleSheep on 2025/4/21.
//
import UIKit
import Kingfisher
class ImageView: UIImageView {
private var _size: CGSize = CGSize(width: 0, height: 0)
// Initialize the image view
override init(frame: CGRect) {
super.init(frame: frame)
contentMode = .scaleAspectFill
clipsToBounds = true
}
required init?(coder: NSCoder) {
super.init(coder: coder)
contentMode = .scaleAspectFill
clipsToBounds = true
}
// Method to set the image from a URL using Kingfisher
func setImage(from url: URL, blurHash: String?) {
let placeholderImage = blurHash != nil ? UIImage.init(blurHash: blurHash!, size: _size) : nil
let processor = DownsamplingImageProcessor(size: _size) |> RoundCornerImageProcessor(cornerRadius: 20)
self.kf.indicatorType = .activity
self.kf.setImage(
with: url,
placeholder: placeholderImage,
options: [
.processor(processor),
.transition(.fade(0.3))
]
)
}
}