如何从服务器导入图像并将其排列在视图中 [英] How to Importing image from server and arrange it in a view

查看:48
本文介绍了如何从服务器导入图像并将其排列在视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to get array of images that have to call from server and arrange that in an order.But while executing below code i can't get it...Guidance please...

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

}

//}

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

now i need to place button image and image from server...

推荐答案

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

这篇关于如何从服务器导入图像并将其排列在视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆