|
7 | 7 |
|
8 | 8 | ## NSURL -> UIImage with cache (swift) |
9 | 9 |
|
10 | | - |
11 | | - |
| 10 | + |
| 11 | + |
| 12 | + |
12 | 13 |
|
13 | 14 | --- |
14 | 15 |
|
| 16 | + |
15 | 17 | # install |
16 | 18 |
|
17 | 19 | - manually |
18 | 20 | - add PIImageCache.swift into your project |
| 21 | +- cocoapods |
| 22 | + - add " pod 'PIImageCache', '0.1.1' " into your Podfile |
| 23 | + - add " import PIImageCache " into your code |
| 24 | + |
| 25 | +# basic usage |
19 | 26 |
|
20 | | -# usage |
| 27 | +## NSURL extension |
21 | 28 |
|
22 | | -- create cache instance |
23 | | -- get image by NSURL extension |
| 29 | +```NSURL.swift |
| 30 | +let url = NSURL(string: "http://place-hold.it/200x200")! |
| 31 | +let image = url.getImageWithCache() |
| 32 | +``` |
24 | 33 |
|
25 | | -# example |
| 34 | +## UIImageView extension |
26 | 35 |
|
| 36 | +```UIImageView.swift |
| 37 | +let url = NSURL(string: "http://place-hold.it/200x200")! |
| 38 | +let imgView = UIImageView() |
| 39 | +imgView.imageOfURL(url) |
27 | 40 | ``` |
28 | | - let url = NSURL(string: "http://place-hold.it/200x200")! |
29 | | - let cache = PIImageCache() |
30 | | - url.getImageWithCache(cache) |
| 41 | + |
| 42 | +## for background |
| 43 | + |
| 44 | +```PIImageCache.swift |
| 45 | +let url = NSURL(string: "http://place-hold.it/200x200")! |
| 46 | +let cache = PIImageCache.shared |
| 47 | +image = cache.get(url)! |
31 | 48 | ``` |
| 49 | + |
| 50 | +# advanced usage |
| 51 | + |
| 52 | +## configurable |
| 53 | + |
| 54 | +```Config.swift |
| 55 | +let cache = PIImageCache.shared |
| 56 | +var config = PIImageCache.Config() |
| 57 | +config.maxCount = 5 |
| 58 | +config.maxByteSize = 100 |
| 59 | +cache.setConfig(config) |
| 60 | + |
| 61 | +let url = NSURL(string: "http://place-hold.it/200x200")! |
| 62 | +let image = cache.get(url)! |
| 63 | +``` |
0 commit comments