-(IBAction)video_icon:(id)sender

{

    

    [self embedYouTube:@"https://www.youtube.com/watch?v=r5Np... ...(공영상 고유코드값)&feature=youtu.be" frame:CGRectMake(20, 20, 1, 1)];

    

    

    /*

     WebView6 *webView6 = [[WebView6 alloc] initWithNibName:@"WebView6" bundle:nil];

     

     [self.tabBarController presentModalViewController:webView6 animated:YES];

     [webView6 release];

     */

}




// 동영상 실행.

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {

NSString *embedHTML = @"\

    <html><head>\

<style type=\"text/css\">\

body {\

background-color: transparent;\

color: white;\

}\

</style>\

</head><body style=\"margin:0\">\

    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" autoplay=\"1\" \

width=\"%0.0f\" height=\"%0.0f\"></embed>\

    </body></html>";

NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];

UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];

videoView.delegate = self;

[videoView loadHTMLString:html baseURL:nil];

[self.view addSubview:videoView];

[videoView release];

}



// 웹뷰의 유튜브 재싱 버튼 클릭.

- (UIButton *)findButtonInView:(UIView *)view {

UIButton *button = nil;

if ([view isMemberOfClass:[UIButton class]]) {

return (UIButton *)view;

}

if (view.subviews && [view.subviews count] > 0) {

for (UIView *subview in view.subviews) {

button = [self findButtonInView:subview];

if (button) return button;

}

}

return button;

}


// 필요에 따라 사용하면 된다. 

// 웹뷰가 로드된 오토플레이 강제 처리.

- (void)webViewDidFinishLoad:(UIWebView *)_webView {

UIButton *b = [self findButtonInView:_webView];

[b sendActionsForControlEvents:UIControlEventTouchUpInside];

}

Posted by 예배하는 프로그래머