is it possible to use iframe in UIWebView?

Piscean picture Piscean · Mar 2, 2011 · Viewed 22.6k times · Source

i want to add a facebook like button in my app. in developer.facebook.com i couldn't fine anything about that. is it possible to use iframe created by facebook like button in UIWebView? it think if its possible then i can add a UIWebView in my app which use that iframe. thanx. please write some example code.

Answer

Sameera Chathuranga picture Sameera Chathuranga · Apr 10, 2013

Yes it is possible, I am using iFrame to load youtube Video inside the app.

Following simple steps will guide you to achieve it.

Step 1 : Create a UIWebView in xib
Step 2 : Connect it to your ViewController's .h file. (I am referring it as _wevView in my project).
Step 3 : Create a method embedYouTube in your ViewController's .m file.

-(void)embedYouTube {
    // Read create a NSString object with iframe
    NSString *embedHTML = @"<iframe width=\"300\" height=\"250\" src=\"http://www.youtube.com/embed/rOPI5LDo7mg\" frameborder=\"0\" allowfullscreen></iframe>";

    // Initialize the html data to webview
    [_webView loadHTMLString:embedHTML baseURL:nil];

    // Add webview to your main view
    [self.view addSubview:_webView];

}

Step 4: Add the webview to your main view by by making a call to the method embedYouTube inside viewDidLoad

[self embedYouTube];

Step 5: Compile and run the app. You should be able to view the YouTube player embedded in the page.