Created
May 25, 2010 19:06
-
-
Save codeclash/413542 to your computer and use it in GitHub Desktop.
UIWebView with Youtube links
This file contains 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 characters
@interface YouTubeView : UIWebView | |
{ | |
} | |
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame; | |
@end | |
#import "YouTubeView.h" | |
@implementation YouTubeView | |
#pragma mark - | |
#pragma mark Initialization | |
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame; | |
{ | |
if (self = [super init]) | |
{ | |
// Create webview with requested frame size | |
self = [[UIWebView alloc] initWithFrame:frame]; | |
// HTML to embed YouTube video | |
NSString *youTubeVideoHTML = @"<html><head>\ | |
<body style=\"margin:0\">\ | |
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ | |
width=\"%0.0f\" height=\"%0.0f\"></embed>\ | |
</body></html>"; | |
// Populate HTML with the URL and requested frame size | |
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height]; | |
// Load the html into the webview | |
[self loadHTMLString:html baseURL:nil]; | |
} | |
return self; | |
} | |
#pragma mark - | |
#pragma mark Cleanup | |
- (void)dealloc | |
{ | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment