2013-06-28 39 views
-2

任何人都可以帮助我请这个问题的数字, 即时尝试创建多个webview,每个webview将包含不同的链接。我现在做的方式是我可以创建5个Web视图,但只包含1个链接。这里是代码ios:多个webview与多个链接

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; 

在此先感谢。

+0

您正在添加相同的链接5次吗? – basar

+0

你究竟想要什么? – user968597

+0

即时通讯设法添加5个不同的链接5网络视图,但我不知道如何。我需要做什么,以4其他链接出现。我不想用不同的链接对webview进行5次编码。 – user2530871

回答

-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; 

}

+0

感谢您的回答。我很欣赏 – user2530871

+0

为什么反对投票? – user968597

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 [email protected]"<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. 

} 
+0

亲爱的Ganapathy,跟随你的代码,如果我有超过5个链接,我将需要做超过5个案例?或者还有其他方法可以做。我也只是添加“如果其他”声明自动放置webview – user2530871

+0

U提到5 webview只有在问题中正确!你需要什么? – Ganapathy

+0

抱歉不能确切地告诉你我想要什么。我想添加20+的webview与20多个链接,我需要代码自动将webview放置在某个xcoord和ycoord中。 – user2530871