Created
April 28, 2011 14:06
-
-
Save danielphillips/946404 to your computer and use it in GitHub Desktop.
Revisions
-
Daniel Phillips revised this gist
Jun 9, 2011 . 5 changed files with 0 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ #import "DJPWebViewDelegate.h" #import "DJPWebViewContent.h" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ #import "DJPWebView.h" @implementation DJPWebView @synthesize content; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,3 @@ @interface DJPWebViewContent : NSObject { NSMutableString* css; NSMutableString* html; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,3 @@ @interface DJPWebViewDelegate : NSObject <UIWebViewDelegate, UIAlertViewDelegate> { NSString* clickedLink; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ #import "DJPWebViewDelegate.h" @implementation DJPWebViewDelegate -(id)init{ -
Daniel Phillips revised this gist
Apr 28, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ -(id)init{ self = [super init]; if(self){ css = [[NSMutableString alloc] initWithString:@"* {-webkit-user-select: none;}"]; [css appendString:[NSString stringWithFormat:@"a:link {color:%@; text-decoration:none}", WEBVIEW_LINK_COLOR]]; [css appendString:[NSString stringWithFormat:@"body { " "margin:0;" "padding:0;" -
Daniel Phillips revised this gist
Apr 28, 2011 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,15 @@ -(id)init{ if(self){ css = [[NSMutableString alloc] initWithString:@"* {-webkit-user-select: none;}"]; [css appendString:[NSString stringWithFormat:@"a:link {color:#3DB6B6; text-decoration:none}", WEBVIEW_LINK_COLOR]]; [css appendString:[NSString stringWithFormat:@"body { " "margin:0;" "padding:0;" "font-family: \"%@\";" "font-size:%d;" "width:290px;" "color:gray}", WEBVIEW_TEXT_FONT, [[NSNumber numberWithFloat:WEBVIEW_TEXT_SIZE] intValue]]]; [css appendString:[NSString stringWithFormat:@"strong { font-family: \"%@\"}", WEBVIEW_BOLD_FONT]]; [css appendString:@"p { margin:0;}"]; [css appendString:@"p+p { margin-top:15px;}"]; -
Daniel Phillips revised this gist
Apr 28, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,10 +31,10 @@ -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)in } UIAlertView* av = [[UIAlertView alloc] initWithTitle:alertText message:clickedLink delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [av show]; [av release]; if(tel){ -
Daniel Phillips revised this gist
Apr 28, 2011 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,11 +28,11 @@ -(void)appendHTMLBody:(NSString*)markup{ -(NSString*)getContentsOfPage{ return [NSString stringWithFormat:@"<html>" "<head>" "<style type=\"text/css\">%@</style>" "</head>" "<body>%@</body>" "</html>", css, html]; } @end -
Daniel Phillips revised this gist
Apr 28, 2011 . 2 changed files with 11 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,12 @@ -(void)appendHTMLBody:(NSString*)markup{ } -(NSString*)getContentsOfPage{ return [NSString stringWithFormat:@"<html>" "<head>" "<style type=\"text/css\">%@</style>" "</head>" "<body>%@</body>" "</html>", css, html]; } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,11 @@ -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)in alertText = @"Follow link"; } UIAlertView* av = [[UIAlertView alloc] initWithTitle:alertText message:clickedLink delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [av show]; [av release]; if(tel){ -
Daniel Phillips created this gist
Apr 28, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ #import <Foundation/Foundation.h> #import "DJPWebViewDelegate.h" #import "DJPWebViewContent.h" @interface DJPWebView : UIWebView { DJPWebViewDelegate* delegateObject; DJPWebViewContent* content; } @property(nonatomic, retain)DJPWebViewContent* content; -(void)display; @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #import "DJPWebView.h" @implementation DJPWebView @synthesize content; -(id)init{ self = [super init]; if(self){ delegateObject = [[DJPWebViewDelegate alloc] init]; [super setDelegate:delegateObject]; ((UIScrollView*)[[super subviews] objectAtIndex:0]).bounces = NO; [super setUserInteractionEnabled:YES]; content = [[DJPWebViewContent alloc] init]; } return self; } -(void)display{ [super loadHTMLString:[content getContentsOfPage] baseURL:[NSURL URLWithString:@""]]; } -(void)dealloc{ [delegateObject release]; [super dealloc]; } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ #import <Foundation/Foundation.h> @interface DJPWebViewContent : NSObject { NSMutableString* css; NSMutableString* html; } -(void)appendCSSRule:(NSString*)style; -(void)appendHTMLBody:(NSString*)markup; -(NSString*)getContentsOfPage; @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ #import "DJPWebViewContent.h" #import "DJPWebViewSettings.h" @implementation DJPWebViewContent -(id)init{ self = [super init]; if(self){ css = [[NSMutableString alloc] initWithString:@"* {-webkit-user-select: none;}"]; [css appendString:[NSString stringWithFormat:@"a:link {color:#3DB6B6; text-decoration:none}", WEBVIEW_LINK_COLOR]]; [css appendString:[NSString stringWithFormat:@"body { margin:0; padding:0; font-family: \"%@\"; font-size:%d; width:290px; color:gray}", WEBVIEW_TEXT_FONT, [[NSNumber numberWithFloat:WEBVIEW_TEXT_SIZE] intValue]]]; [css appendString:[NSString stringWithFormat:@"strong { font-family: \"%@\"}", WEBVIEW_BOLD_FONT]]; [css appendString:@"p { margin:0;}"]; [css appendString:@"p+p { margin-top:15px;}"]; html = [[NSMutableString alloc] initWithString:@""]; } return self; } -(void)appendCSSRule:(NSString*)style{ [css appendString:style]; } -(void)appendHTMLBody:(NSString*)markup{ [html appendString:markup]; } -(NSString*)getContentsOfPage{ return [NSString stringWithFormat:@"<html><head><style type=\"text/css\">%@</style></head><body>%@</body></html>", css, html]; } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ #import <Foundation/Foundation.h> @interface DJPWebViewDelegate : NSObject <UIWebViewDelegate, UIAlertViewDelegate> { NSString* clickedLink; } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ #import "DJPWebViewDelegate.h" @implementation DJPWebViewDelegate -(id)init{ self = [super init]; if(self){ clickedLink = [[NSString alloc] init]; } return self; } -(void)dealloc{ [clickedLink release]; [super dealloc]; } -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { if ( inType == UIWebViewNavigationTypeLinkClicked ) { clickedLink = [NSString stringWithFormat:@"%@",[inRequest URL]]; NSString* alertText; BOOL tel = NO; if([[clickedLink substringToIndex:3] isEqualToString:@"tel"]){ alertText = @"Call"; clickedLink = [clickedLink substringFromIndex:4]; clickedLink = [clickedLink stringByReplacingOccurrencesOfString:@"%20" withString:@" "]; tel = YES; }else{ alertText = @"Follow link"; } UIAlertView* av = [[UIAlertView alloc] initWithTitle:alertText message:clickedLink delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [av show]; [av release]; if(tel){ clickedLink = [clickedLink stringByReplacingOccurrencesOfString:@" " withString:@""]; clickedLink = [[NSString stringWithFormat:@"tel:%@", clickedLink] retain]; } return NO; } return YES; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ switch (buttonIndex) { case 0: { NSLog(@"user cancelled"); } break; case 1: { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:clickedLink]]; } break; default: break; } } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ #define WEBVIEW_LINK_COLOR @"#3DB6B6" #define WEBVIEW_TEXT_FONT @"Avant Guard IOS" #define WEBVIEW_TEXT_SIZE 12.5f #define WEBVIEW_BOLD_FONT @"Avant Garde Demi IOS"