Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added docs about working with remote images, added a link to Programm…

…ing Guide in Readme
  • Loading branch information...
commit 518add305543a1e8b3fbbf39fcfc55f01589c34c 1 parent 5467930
@zen4ever zen4ever authored
View
42 Documentation/Programming Guide-template.markdown
@@ -98,3 +98,45 @@ When creating a DTCoreTextLayoutFrame you can specify the maximum width and heig
DTCoreTextLayoutFrame *layoutFrame = [layouter layoutFrameWithRect:maxRect range:entireString];
CGSize sizeNeeded = [layoutFrame frame].size;
+
+
+Displaying remote images
+------------------------
+
+The best way to display remote images is to use `DTLazyImageView`.
+First you will need to return `DTLazyImageView` instance for your image attachments.
+
+```objective-c
+ - (UIView *)attributedTextContentView:(DTAttributedTextContentView *)attributedTextContentView viewForAttachment:(DTTextAttachment *)attachment frame:(CGRect)frame{
+ if([attachment isKindOfClass:[DTImageTextAttachment class]]){
+ DTLazyImageView *imageView = [[DTLazyImageView alloc] initWithFrame:frame];
+ imageView.delegate = self;
+
+ // url for deferred loading
+ imageView.url = attachment.contentURL;
+ return imageView;
+ }
+ return nil;
+ }
+```
+
+Then in the in delegate method for `DTLazyImageView` reset the layout for the affected `DTAttributedContextView`.
+
+```objective-c
+ - (void)lazyImageView:(DTLazyImageView *)lazyImageView didChangeImageSize:(CGSize)size {
+ NSURL *url = lazyImageView.url;
+ NSPredicate *pred = [NSPredicate predicateWithFormat:@"contentURL == %@", url];
+
+ // update all attachments that matching this URL
+ for (DTTextAttachment *oneAttachment in [self.attributedTextContentView.layoutFrame textAttachmentsWithPredicate:pred]) {
+ oneAttachment.originalSize = size;
+ }
+
+ // need to reset the layouter because otherwise we get the old framesetter or cached layout frames
+ self.attributedTextContentView.layouter = nil;
+
+ // here we're layouting the entire string,
+ // might be more efficient to only relayout the paragraphs that contain these attachments
+ [self.attributedTextContentView relayoutText];
+ }
+```
View
2  Readme.markdown
@@ -17,6 +17,8 @@ Documentation can be [browsed online](https://docs.cocoanetics.com/DTCoreText) o
A [Q&A](http://www.cocoanetics.com/2011/08/nsattributedstringhtml-qa/) answers some frequently asked questions.
+There is also a [Programming Guide](Documentation/Programming Guide-template.markdown) with a set of solutions to common problems.
+
Follow [@cocoanetics](http://twitter.com/cocoanetics) on Twitter or subscribe to the [Cocoanetics Blog](http://www.cocoanetics.com) for news and updates.
#### Changelog
Please sign in to comment.
Something went wrong with that request. Please try again.