Intro to DTCoreText: Moving Past UIWebView | iOS Development
Upcoming SlideShare
Loading in...5
×
 

Intro to DTCoreText: Moving Past UIWebView | iOS Development

on

  • 2,229 views

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

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

Statistics

Views

Total Views
2,229
Slideshare-icon Views on SlideShare
2,229
Embed Views
0

Actions

Likes
1
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Intro to DTCoreText: Moving Past UIWebView | iOS Development Intro to DTCoreText: Moving Past UIWebView | iOS Development Presentation Transcript

    • 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:@"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;
    • 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;}
    • 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" 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;
    • 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];}
    • BenefitsIt’s not a hammer...“Native”Bonus: Improved Typography
    • DrawbacksLimited HTML/CSS SupportNo Text Selection
    • github.com/cocoanetics/DTCoreText
    • @smartlogicfacebook.com/smartlogicgithub.com/smartlogic