LMFeedImageView
Overview
The LMFeedImageView
is an enhanced image view that extends UIImageView
to provide convenient asynchronous image loading, caching, and cancellation. It is designed for use in feed-style UIs where images are loaded from URLs and may change frequently.
File Location:
LMFeedImageView.swift
Functionality
UI Components
image
: The displayed imagelastUrlLoaded
: The last URL loaded into the image view
Methods
translatesAutoresizingMaskIntoConstraints() -> Self
: Disables autoresizing mask translation and returns self for chainingloadImage(url:completionHandler:)
: Loads an image from a URL asynchronouslyloadImage(url:to:scale:completionHandler:)
: Loads an image with a target size and scaledeloadImageView()
: Clears the image and resets the state
Customization
CustomFeedImageView.swift
class CustomFeedImageView: LMFeedImageView {
override init(frame: CGRect) {
super.init(frame: frame)
// Custom setup
}
// Add customizations as needed
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.imageView = CustomFeedImageView.self
// ...
return true
}