-2

谁能帮我解决这个问题,我试图创建多个 webview,每个 webview 将包含不同的链接。我现在做的方式是我可以创建 5 个 webview 但只包含 1 个链接。这是代码

 NSInteger i;
int xCoord = 0;
int yCoord = 0;
int webWidth = 80;
int webHieght = 80;
int buffer = 10;

for (i = 1; i <=5; i++)
{
    UIWebView *video =[[UIWebView alloc] initWithFrame:CGRectMake(xCoord , yCoord,   webWidth, webHieght)];
    NSString *link = @"<iframe width=\"70\" height=\"70\" src=\"http://www.youtube.com/embed/BELlZKpi1Zs\" frameborder=\"0\" allowfullscreen></iframe>";
    [video loadHTMLString:link baseURL:nil];
    [video setBackgroundColor:[UIColor clearColor]];
    [video setOpaque:NO];
    [scrollview addSubview:video];

    yCoord += webHieght + buffer;

提前致谢。

4

2 回答 2

0

您需要自定义代码。

-(void)setWebiewDetails
{
    NSArray *UrlArray;
    CGFloat x=0;
    CGFloat y=0;
    int endOfXco = 320;// iphone
    int noofrow = 1;
    for(NSString *url in UrlArray)
    {
        [self createWebView:url Frame:CGRectMake(x, y, 100, 100)];
        x+=110;
        if(x>endOfXco)
        //End of x co.
        {
            x = 0;
            y = noofrow * 110;
            noofrow++;
            // increasing rows
        }
    }
}
-(void)createWebView:(NSString *)URL Frame:(CGRect)frame
{

    UIWebView *video =[[UIWebView alloc] initWithFrame:frame];
    NSString *link =@"<iframe width=\"70\" height=\"70\" src=\"http://www.youtube.com/embed/BELlZKpi1Zs\" frameborder=\"0\" allowfullscreen></iframe>";//Customize the URL
    [video loadHTMLString:link baseURL:nil];
    [video setBackgroundColor:[UIColor clearColor]];
    [video setOpaque:NO];
    [scrollview addSubview:video]; // Based on total web views(noofrows) you need to manage the scroll view's content offset.

}
于 2013-06-28T11:19:04.407 回答
-1
   NSInteger i;
   int xCoord = 0;
   int yCoord = 0;
   int webWidth = 80;
   int webHieght = 80;
   int buffer = 10;

    NSMutableArray *links = [NSMutableArray arrayWithObjects:@"link 1",@"link 2",@"link   3",@"link 4",@"link 5",nil];

  for (i = 1; i <=5; i++)
 {
   UIWebView *video =[[UIWebView alloc] initWithFrame:CGRectMake(xCoord , yCoord,   webWidth, webHieght)];
     NSString *link = [links objectAtIndex:i];
    [video loadHTMLString:link baseURL:nil];
    [video setBackgroundColor:[UIColor clearColor]];
    [video setOpaque:NO];
    [scrollview addSubview:video];

    yCoord += webHieght + buffer;

}

于 2013-06-28T11:11:04.247 回答