图像的缩略图网格

时间:2011-02-17 13:21:55

标签: iphone

如何创建动态缩略图网格?

如何使用iphone上的照片应用程序等图像缩略图创建网格?

这些空间如何动态排列?例如添加和删​​除缩略图。

1 个答案:

答案 0 :(得分:1)

这是我的简单网格视图应用

   - (void)viewDidAppear:(BOOL)animated {
[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView];
temp = temp+1;
if (temp ==1){
NSLog(@"temp:%d",temp);
int n = 20;     //Numbers of array;
NSArray *t = [[NSArray alloc] initWithObjects:@"calpie.gif",@"chrysler_electric.png",@"chrysler_fiat_cap.gif",@"cleanup.gif",@"ecylindri.gif",@"elect08.png",@"globe.gif",@"heat.gif",@"insur.gif"
     ,@"jobs.gif",@"office.gif",@"opec1.gif",@"orng_cap.gif",@"poll.gif",@"pollen.gif",@"purbar.gif",@"robinson.gif",@"robslink_cap.gif",@"scot_cap.gif",@"shoes.gif",nil];

myScrollView.contentSize = CGSizeMake(320, 460+n*2);    
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 1;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;


NSString *mxiURL = @"http://meta-x.com/biflash/images/";
int i =0,i1=0; 
while(i<n){
    int yy = 4 +i1*79;
    for(int j=0; j<4;j++){
        if (i>=n) break;
        CGRect rect;
        rect = CGRectMake(4+79*j, yy, 75, 75);
        UIButton *button=[[UIButton alloc] initWithFrame:rect];
        [button setFrame:rect];
        NSString *nn = [mxiURL stringByAppendingString:[t objectAtIndex:i]];
        UIImage *buttonImageNormal=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: nn]]];

        [button setBackgroundImage:buttonImageNormal    forState:UIControlStateNormal];
        button.tag =i;
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
        //[self.view addSubview:button];


        [myScrollView addSubview:button];
        //[buttonImageNormal release];
        [button release];
        i++;
        //
    }
    i1 = i1+1;

    //i=i+4;

}
  }

   }
AppDelegate中的

  + (Grid_ViewAppDelegate *)sharedAppDelegate
 {
return (Grid_ViewAppDelegate *)[UIApplication sharedApplication].delegate;
}

- (void)showLoadingView
 {
if (loadingView == nil)
{
    loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
    loadingView.opaque = NO;
    loadingView.backgroundColor = [UIColor grayColor];
    loadingView.alpha = 0.5;

    UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
    [spinningWheel startAnimating];
    spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [loadingView addSubview:spinningWheel];
    [spinningWheel release];

    CGRect label = CGRectMake(142.0f, 255.0f, 71.0f, 20.0f);
    lblLoading = [[UILabel alloc] initWithFrame:label];
    lblLoading.textColor = [UIColor whiteColor];
    lblLoading.font = [UIFont boldSystemFontOfSize:14];
    //  UILabel
    lblLoading.backgroundColor =[UIColor clearColor];
    [lblLoading setText:@"Loading..."];
    //[lblLoading setTextAlignment:UITextAlignmentCenter];
    [loadingView addSubview:lblLoading];


  }

[window addSubview:loadingView];

}

- (void)hideLoadingView
{
[loadingView removeFromSuperview];
}

绝对是你应用这个逻辑。你成功了