A very simple iOS image loader library written in Swift
with in-memory cache support using NSCache
.
Create a file named Cartfile
inside your root project, and add this to the Cartfile
:
github "zambelz48/ZIMGLoader" "v1.0.1"
Open terminal and execute this :
carthage update --platform iOS
let option = ImageRequestOption(
urlString: "http://www.image-url.com",
placeholderImage: nil,
loadingIndicator: nil
)
imageView.loadImage(with: option)
let placeholderImage = UIImage(named: "your_placeholder_image")
let indicatorView = UIActivityIndicatorView(style: .whiteLarge)
indicatorView.startAnimating()
let option = ImageRequestOption(
urlString: "http://www.image-url.com",
placeholderImage: placeholderImage,
loadingIndicator: indicatorView
)
imageView.loadImage(with: option)
...
imageView.loadImage(with: option) {
print("Finish load image")
}
let option = ImageRequestOption(
urlString: "", // Image url (Mandatory)
placeholderImage: UIImage?, // Placeholder image (Optional)
loadingIndicator: UIView?, // Indicator view when loading an image (Optional)
contentMode: UIView.ContentMode, // Content mode (default value is : `.scaleToFill`)
cached: Bool // Flag whether the image should store in cache (default value is : `true`)
)
This library is used NSCache
, which is only support in-memory cache strategy. And by default every successful download operation the image will be stored in cache. If you don't want to store in cache, set cached
flag in ImageRequestOption
into false
.
let desiredMaxCapacity = 200 // in MB
ImageCacheHandler.shared.setCache(maxCapacity: desiredMaxCapacity)
ImageCacheHandler.shared.clearCachedImages()