2011-02-17 124 views
1

如何創建動態縮略圖網格?圖像的縮略圖網格

如何用iPhone上的照片應用程序的圖像縮略圖創建網格?

這些空間是如何動態佈置的?例如添加和刪​​除縮略圖。

回答

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

肯定,如果ü應用此邏輯。你成功了

+0

謝謝。這是什麼用於[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView]; – jarryd 2011-02-17 13:35:15