Created
June 9, 2017 04:01
-
-
Save truongngoclinh/b3d973e49707fd656d7fe4b8205a65e7 to your computer and use it in GitHub Desktop.
iOS 100%width youtube vide embed
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
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.mWebView.delegate = self; | |
[self.mWebView loadHTMLString:self.video.videoIframe baseURL:nil]; | |
} | |
- (void)webViewDidFinishLoad:(UIWebView *)webView { | |
NSString *css = @".container {position: relative; width: 100%; height: 0; padding-bottom: 56.25%;}.video {position: absolute; top: 0; left: 0; width: 100%; height: 100%;} "; | |
NSString* js = [NSString stringWithFormat: | |
@"var styleNode = document.createElement('style');\n" | |
"styleNode.type = \"text/css\";\n" | |
"var styleText = document.createTextNode('%@');\n" | |
"styleNode.appendChild(styleText);\n" | |
"document.getElementsByTagName('head')[0].appendChild(styleNode);\n",css]; | |
NSLog(@"js:\n%@",js); | |
[self.mWebView stringByEvaluatingJavaScriptFromString:js]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment