请有人帮我解决这个问题, 我试图创建多个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;
提前感谢。
答案 0 :(得分: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.
}
答案 1 :(得分:-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;
}