B. Money
B. Money

Reputation: 931

Why Is Youtube Video Not Filling UiWebView?

I'm a noob to iphone development and I am having trouble displaying an embedded youtube video within a UIwebview. Currently, the youtube video sits in the top left hand corner of the uiwebview and it also has an annoying border. I set the youtube frame to the same dimensions as my uiwebview and the webview is set to "scale to fit". How do I make my youtube content fit the entire screen and get rid of the border? Any help is greatly appreciated.

MY CODE

NSString *video_ID = youtubeid;
NSString *htmlStr = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"320\" height=\"230\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe>",video_ID];
[videoScreen loadHTMLString:htmlStr baseURL:nil]; 

EDIT

 NSString *video_ID = youtubeid;
NSString *htmlStr = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"100%\" height=\"100%\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe>",video_ID];
[videoScreen loadHTMLString:htmlStr baseURL:nil]; 

Upvotes: 6

Views: 3430

Answers (3)

user1377947
user1377947

Reputation:

So here I scan through all the buttons in the webview and select the first button found using the sendActionsForControlEvents function.

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 = findButtonInView( subview );  
    if( button )   
    {  
      return button;  
  }  
   }  
    }  

     return button;  
      }  

    -(void)webViewDidFinishLoad:(UIWebView*)webView  
     {  
    UIButton *button = findButtonInView( webView );  
      if( button != nil )  
       {  
      [button sendActionsForControlEvents:UIControlEventTouchUpInside];  
  }  
   }  

Upvotes: 0

user1377947
user1377947

Reputation:

So first you must create a UIWebView and add it to your main view. In the following I create a webview pointing to www.example.com where I have embedding the YouTube clip I want to play, I set it hidden because I'll later want to launch the video full screen.`

UIWebView *htmlView;
 htmlView = [[UIWebView alloc] initWithFrame:CGRectMake( 55.0f, 105.0f, 369.0f, 178.0f) ];  
  [htmlView setBackgroundColor:[UIColor blackColor]];  
    htmlView.hidden = YES;  
     htmlView.delegate = self;  
      [self addSubview:htmlView];  
       [htmlView loadRequest:[NSURLRequest requestWithURL:[NSURL   URLWithString:@"www.example,com"]]];  `

Upvotes: 0

NULL
NULL

Reputation: 1858

Have u tried this......

NSString *video_ID = youtubeid;
NSString *htmlStr = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"100%%\" height=\"100%%\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe>",video_ID];
[videoScreen loadHTMLString:htmlStr baseURL:nil];

Note That %% is used for % character.

Upvotes: 6

Related Questions