https://github.com/davecom/dkasyncimageview
A Swift subclass of NSImageView for loading remote images asynchronously.
https://github.com/davecom/dkasyncimageview
Last synced: about 1 year ago
JSON representation
A Swift subclass of NSImageView for loading remote images asynchronously.
- Host: GitHub
- URL: https://github.com/davecom/dkasyncimageview
- Owner: davecom
- License: mit
- Created: 2014-10-10T00:12:28.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-11-19T08:38:31.000Z (over 2 years ago)
- Last Synced: 2025-04-18T00:44:54.254Z (about 1 year ago)
- Language: Swift
- Size: 52.7 KB
- Stars: 47
- Watchers: 7
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DKAsyncImageView
================
[](https://swift.org)
[](https://cocoapods.org/pods/DKAsyncImageView)
[](https://swift.org/package-manager/)
[](https://cocoapods.org/pods/DKAsyncImageView)
[](https://twitter.com/davekopec)
DKAsyncImageView is a Swift subclass of NSImageView for loading remote images asynchronously and displaying them on OS X.
This class was originally a port of [PVAsyncImageView](https://github.com/pedrovieira7/PVAsyncImageView) by [@pedrovieira7](https://github.com/pedrovieira7) from Objective-C to Swift.
Features
----------------
* Download images from the Web to DKAsyncImageView asynchronously with just 1 line of code
* Set a 'Placeholder Image' to be displayed until the image is downloaded
* Set an 'Error Image' to be displayed when an error occurs while downloading the image
* Set ToolTips for each state -> Loading Image / Image Loaded / Error Loading Image
* Display a Spinning Wheel on top of DKAsyncImageView while it's downloading the image
* No external dependencies beyond AppKit
Documentation
----------------
Include `DKAsyncImageView.swift` in your project, use the CocoaPod `DKAsyncImageView`, or use SPM with this repository as your dependency. Set an IB NSImageView's class as DKAsyncImageView or create it programmatically. In the latter case, use the standard NSImageView init methods.
> Note: DKAsyncImageView 1.0.3/1.0.4 supports Swift 4 and Swift 5. Version 1.0.2 supports Swift 3. Version 1.0.1 supports Swift 2. Version 1.0 supports Swift 1.2.
**Download an Image**
```
func downloadImageFromURL(url: String, placeHolderImage: NSImage? = nil, errorImage: NSImage? = nil, usesSpinningWheel: Bool = false, completion: ((Data?, Error?) -> Void)? = nil)
```
At minimum, you simply must provide the URL of the image you want to asynchronously download. However, you also have the option of providing a `placeHolderImage` that displays while the download is taking place, and an `errorImage` that displays if the download is unsuccessful.
`usesSpinningWheel` specifies whether a spinning NSProgressIndicator appears over the NSImageView while the image is being downloaded.
`completion` is a block to be executed when the download task finishes
**Set Tool Tips**
```
func setToolTipWhileLoading(ttip1: String?, whenFinished ttip2:String?, andWhenFinishedWithError ttip3: String?)
```
**Cancel a Download**
```
cancelDownload()
```
There are no external dependencies other than the AppKit framework.
Future Direction/Ideas
----------------
* Make property based instead of method based