gpt4 book ai didi

iphone - 如何从服务器导入图像并将其排列在 View 中

转载 作者:行者123 更新时间:2023-12-01 18:00:06 24 4
gpt4 key购买 nike

我需要获取必须从服务器调用的图像数组并将其按顺序排列。但是在执行以下代码时我无法获取它...指导请...

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

NSURL *url = [NSArray arrayWithObjects:[NSURL URLWithString:
@"http://images.wikia.com/marvelmovies/images/5/5e/The-hulk-2003.jpg"],
[NSURL URLWithString:@"http://cdn.gottabemobile.com/wp-content/uploads/2012/06/ios62.jpg"],
[NSURL URLWithString:@"http://challenge.roadef.org/2012/img/google_logo.jpg"],
[NSURL URLWithString:@"http://addyosmani.com/blog/wp-content/uploads/2012/03/Google-doodle-of-Richard-007.jpg"],
[NSURL URLWithString:@"http://techcitement.com/admin/wp-content/uploads/2012/06/apple-vs-google_2.jpg"],
[NSURL URLWithString:@"http://www.andymangels.com/images/IronMan_9_wallpaper.jpg"],
[NSURL URLWithString:@"http://sequelnews.com/wp-content/uploads/2011/11/iphone_5.jpg"],Nil];

/*
int i=0;
int cord_x=0;
int cord_y=30;
int cont=0;

for (i = 0; i < [(NSArray*)url count]; i++) {
cont=cont+1;
if (cont > 3) {
cord_x=0;
cord_y=cord_y+110;
cont=1;
}*/

UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:(NSURL*)[(NSArray*)url objectAtIndex:index]]];

//cord_x=cord_x+110;



UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200.0f, 200.0f);

[button setImage:(UIImage*)[image objectAtIndex:index] forState:UIControlStateNormal];

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return button;

}

//}

现在我需要放置按钮图像和来自服务器的图像...

最佳答案

 int row = 0;
int column = 0;

for(int i = 0; i < url.count; ++i) {
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:(NSURL*) [(NSArray*)url objectAtIndex:i]]];

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*100+16, row*90, 80, 80);
[button setImage:image forState:UIControlStateNormal];

[button addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[self.view addSubview:button];

if (column == 2) {
column = 0;
row++;
} else {
column++;
}
}

关于iphone - 如何从服务器导入图像并将其排列在 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11220795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com