Skip to content

Commit 68f394e

Browse files
committed
Update the readme about the usage
1 parent d226877 commit 68f394e

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

897 KB
Loading

Example/Screenshot/LinkDemo.png

1.18 MB
Loading

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,50 @@ let package = Package(
4747

4848
## Usage
4949

50-
TODO
50+
#### Setup Loader
51+
52+
To use the LinkPlugin, you should setup the loader firstly. See more here in [Wiki - Loaders Manager](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#loaders-manager)
53+
54+
+ Objective-C
55+
56+
```objective-c
57+
[SDImageLoadersManager.sharedManager addLoader:SDImageLinkLoader.sharedLoader];
58+
SDWebImageManager.defaultImageLoader = SDImageLoadersManager.sharedManager;
59+
```
60+
61+
#### Load Rich Link on UIImageView/LPLinkView
62+
63+
The simple and fast usage, it to use the LinkPlugin provided category on `UIImageView` and `LPLinkView`.
64+
65+
+ Objective-C
66+
67+
```objectivec
68+
NSURL *url1 = [NSURL URLWithString:@"https://www.apple.com/iphone/"];
69+
NSURL *url2 = [NSURL URLWithString:@"https://webkit.org/"];
70+
self.linkView = [[LPLinkView alloc] initWithURL:url1];
71+
self.imageView = [[UIImageView alloc] init];
72+
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
73+
[self.view addSubview:self.linkView];
74+
[self.view addSubview:self.imageView];
75+
76+
[self.linkView sd_setImageWithURL:url1 placeholderImage:nil options:SDWebImageFromLoaderOnly completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
77+
NSLog(@"%@", @"LPLinkView metadata load success");
78+
}];
79+
[self.imageView sd_setImageWithURL:url2 completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
80+
NSLog(@"%@", @"UIImageView image load success");
81+
}];
82+
```
83+
84+
Note: You can always read and write the `LPMetadata` object on the associated `NSURL` object, to provide an exist metadata from your serialization solution, or update the metadata. If the provided URL have an associated metadata, we don't do extra query with [LPMetadataProvider](https://developer.apple.com/documentation/linkpresentation/lpmetadataprovider?language=objc).
85+
86+
+ Objective-C
87+
88+
```objective-c
89+
LPLinkMetadata *metadata = imageURL.sd_linkMetadata;
90+
NSLog(@"[title]: %@\n[url]: %@\n[image]: %@", metadata.title, metadata.URL, metadata.imageProvider);
91+
```
92+
93+
Note: By default, we prefer to load the image only, which does not generate the image data. This can increase the loading speed. But however, you can also specify to generate the image data by using `SDWebImageContextLinkRequestImageData` context option.
5194

5295
## Demo
5396

@@ -61,6 +104,13 @@ open SDWebImageLinkPlugin.xcworkspace
61104

62105
After the Xcode project was opened, click `Run` to build and run the demo.
63106

107+
## Screenshot
108+
109+
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageLinkPlugin/master/Example/Screenshot/LinkDemo.png" width="300" />
110+
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageLinkPlugin/master/Example/Screenshot/LinkDemo-macOS.png" width="600" />
111+
112+
These rich link image is from the [Apple site](https://www.apple.com/) and [WebKit site](https://webkit.org/).
113+
64114
## Author
65115

66116
DreamPiggy

0 commit comments

Comments
 (0)