Youtube player view in iOS

#pragma mark - UIWebViewFactory

+ (UIWebView *)youtubePlayerViewWithFrame:(CGRect)frame andURLString:(NSString *)URLString {
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    videoView.backgroundColor = [UIColor clearColor];
    videoView.opaque = NO;
    NSString *videoHTML = [NSString stringWithFormat:@"\
                           <style type=\"text/css\">\
                           iframe {position:absolute; top:0; margin-top:0px;}\
                           body {background-color:#000; margin:0;}\
                           <iframe width=\"%0.0f\" height=\"%0.0f\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
                           </html>", frame.size.width, frame.size.height, [ACMUtility youtubeEmbededURLStringFromURLString:URLString]];
    [videoView loadHTMLString:videoHTML baseURL:nil];
    return videoView;


How to call this method:

                UIWebView *videoView = [CommonClass youtubePlayerViewWithFrame:view.bounds andURLString:attrib.source];
                videoView.tag = 2;
                [view addSubview:videoView];


Popular posts from this blog

How to show activity indicator in watch kit

Vector graphics in iOS

Exception Handling - Objective C