Intro to DTCoreTextTom von Schwerdtner@tvonwww.smartlogicsolutions.comMoving past UIWebView
DTCoreTextTools for using HTML with CoreText“Using HTML without UIWebView”
Why?HTML is ubiquitous(I don’t really think I need to convince anyone of this)How to present this to users?
UIWebView
UIWebView// Common to all implementationsNSString* filePath = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"h...
UIWebView#pragma mark - UIWebViewDelegate// Open external links from this UIWebView in MobileSafari- (BOOL)webView:(UIWebV...
BenefitsFunctionalSupports bulk of HTML/CSS
DrawbacksWhen all you have is a hammer...Need to adjust text with CSSHackish
DTCoreText(DTAttributedTextView)
DTAttributedTextView// Common to all implementationsNSString* filePath = [[NSBundle mainBundle] pathForResource:@"content"...
DTAttributedTextView#pragma mark - DTAttributedTextContentViewDelegate- (UIView *)attributedTextContentView:(DTAttributedT...
BenefitsIt’s not a hammer...“Native”Bonus: Improved Typography
DrawbacksLimited HTML/CSS SupportNo Text Selection
github.com/cocoanetics/DTCoreText
@smartlogicfacebook.com/smartlogicgithub.com/smartlogic
Upcoming SlideShare
Loading in …5
×

Intro to DTCoreText: Moving Past UIWebView | iOS Development

2,906 views
2,631 views

Published on

Check out this intro to DTCoreText which will help you move past UIWebView. Improve your iOS development skills.

Published in: Technology, Design
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,906
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Intro to DTCoreText: Moving Past UIWebView | iOS Development

  1. 1. Intro to DTCoreTextTom von Schwerdtner@tvonwww.smartlogicsolutions.comMoving past UIWebView
  2. 2. DTCoreTextTools for using HTML with CoreText“Using HTML without UIWebView”
  3. 3. Why?HTML is ubiquitous(I don’t really think I need to convince anyone of this)How to present this to users?
  4. 4. UIWebView
  5. 5. UIWebView// Common to all implementationsNSString* filePath = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"html"];NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];// Wrap our HTML content in the default native font face and sizeNSString *wrappedHTMLString = [NSString stringWithFormat:@"""<style type=text/css>""* { font-family: helvetica; font-size: 12px; }""</style>""%@",htmlString];[self.webView loadHTMLString:wrappedHTMLString baseURL:nil];// Remove the shadow that is displayed when scrolling past the boundsfor (UIView *shadowView in self.webView.scrollView.subviews) {if ([shadowView isKindOfClass:[UIImageView class]]) {[shadowView setHidden:YES];}}// Assign our delegate so we can handle opening links in Mobile Safariself.webView.delegate = self;
  6. 6. UIWebView#pragma mark - UIWebViewDelegate// Open external links from this UIWebView in MobileSafari- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType{if(navigationType == UIWebViewNavigationTypeLinkClicked) {[[UIApplication sharedApplication] openURL:[request URL]];return NO;}return YES;}
  7. 7. BenefitsFunctionalSupports bulk of HTML/CSS
  8. 8. DrawbacksWhen all you have is a hammer...Need to adjust text with CSSHackish
  9. 9. DTCoreText(DTAttributedTextView)
  10. 10. DTAttributedTextView// Common to all implementationsNSString* filePath = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"html"];NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];// Set our builder to use the default native font face (uses Times otherwise)NSDictionary *builderOptions = @{DTDefaultFontFamily: @"Helvetica"};DTHTMLAttributedStringBuilder *stringBuilder = [[DTHTMLAttributedStringBuilder alloc] initWithHTML:htmlDataoptions:builderOptionsdocumentAttributes:nil];self.textView.attributedString = [stringBuilder generatedAttributedString];// Assign our delegate, this is required to handle link eventsself.textView.textDelegate = self;
  11. 11. DTAttributedTextView#pragma mark - DTAttributedTextContentViewDelegate- (UIView *)attributedTextContentView:(DTAttributedTextContentView *)attributedTextContentViewviewForLink:(NSURL *)urlidentifier:(NSString *)identifierframe:(CGRect)frame{DTLinkButton *linkButton = [[DTLinkButton alloc] initWithFrame:frame];linkButton.URL = url;[linkButton addTarget:self action:@selector(linkButtonClicked:) forControlEvents:UIControlEventTouchUpInside];return linkButton;}#pragma mark - Events- (IBAction)linkButtonClicked:(DTLinkButton *)sender{[[UIApplication sharedApplication] openURL:sender.URL];}
  12. 12. BenefitsIt’s not a hammer...“Native”Bonus: Improved Typography
  13. 13. DrawbacksLimited HTML/CSS SupportNo Text Selection
  14. 14. github.com/cocoanetics/DTCoreText
  15. 15. @smartlogicfacebook.com/smartlogicgithub.com/smartlogic

×