Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Minor changes in programming guide and DTAttributedTextCell #717

Merged
merged 2 commits into from

2 participants

@depl0y

Added an options parameter to the setHTML method of the DTAttributedTextCell (default method overloaded).
Added a sample to the Programming Guide on how to change font size and type.

depl0y added some commits
@depl0y depl0y Added example
Added a new example to the Programming Guide showing how to change the default font and font size.
33e3679
@depl0y depl0y Options for HTML
Render HTML with options.
bfae529
@Cocoanetics Cocoanetics merged commit 12bda3c into Cocoanetics:develop
@Cocoanetics
Owner

Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 7, 2014
  1. @depl0y

    Added example

    depl0y authored
    Added a new example to the Programming Guide showing how to change the default font and font size.
  2. @depl0y

    Options for HTML

    depl0y authored
    Render HTML with options.
This page is out of date. Refresh to see the latest.
View
9 Core/Source/DTAttributedTextCell.h
@@ -47,6 +47,15 @@
*/
- (void)setHTMLString:(NSString *)html;
+/**
+ This method allows to set HTML text directly as content of the receiver.
+
+ This will be converted to an attributed string.
+ @param html The HTML string to set as the receiver's text content
+ @param options The options used for rendering the HTML
+ */
+- (void) setHTMLString:(NSString *)html options:(NSDictionary*) options;
+
/**
@name Getting Information
View
9 Core/Source/DTAttributedTextCell.m
@@ -194,7 +194,11 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- (void)setHTMLString:(NSString *)html
{
- // we don't preserve the html but compare it's hash
+ [self setHTMLString:html options:nil];
+}
+
+- (void) setHTMLString:(NSString *)html options:(NSDictionary*) options {
+
NSUInteger newHash = [html hash];
if (newHash == _htmlHash)
@@ -205,10 +209,11 @@ - (void)setHTMLString:(NSString *)html
_htmlHash = newHash;
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
- NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data documentAttributes:NULL];
+ NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data options:options documentAttributes:NULL];
self.attributedString = string;
[self setNeedsLayout];
+
}
- (void)setAttributedString:(NSAttributedString *)attributedString
View
16 Documentation/Programming Guide-template.markdown
@@ -156,3 +156,19 @@ Then in the in delegate method for `DTLazyImageView` reset the layout for the af
[self.attributedTextContentView relayoutText];
}
```
+
+Changing the default font and font size
+---------------------------------------
+When you want to render the HTML in a different font and fontsize, you need to specify this using the `options` parameter.
+
+```
+NSDictionary* options = @{ NSTextSizeMultiplierDocumentOption: [NSNumber numberWithFloat: 1.0],
+ DTDefaultFontFamily: @"Helvetica Neue",
+ };
+
+NSString *html = @"<p>Some Text</p>";
+NSData* descriptionData = [html dataUsingEncoding:NSUTF8StringEncoding];
+NSAttributedString* attributedDescription = [[NSAttributedString alloc] initWithHTMLData:descriptionData options:options documentAttributes:NULL];
+```
+
+
Something went wrong with that request. Please try again.