2009-10-26 86 views

回答

3

所以,如果你想有一個4×4格畫面(即是20×20),每個例如,你可以使用一個滾動視圖,並添加的UIImageViews它像

UIScrollView *s= [[UIScrollView alloc] initWithFrame:someFrame] 
int position x=10; 
int position y=10; 
for(int i=1; i<=pictures.count; i++) 
{ 
    UIImageView *image= [[UIImageView alloc] initWithFrame:CGRectMake(x,y,20,20)] 
    image.image=[UIImage imageNamed:..] //initialize the image for the view 
    [s addSubview:image]; 
    if(i%4==0) //means you need to start a new row 
    { 
      y+=20; //you can tweak this to make it look how you like 
      x=10; //come back to the beggining 
    } 
    else 
     x+=10; //again tweak this to make it "look" right 

} 
1

我的標準答案:在Three20 project檢查出TTPhotoViewController

TTPhotoViewController模仿蘋果的 照片應用程序及其所有輕彈N」 捏的喜悅。您可以提供自己的 「照片來源」,它的作品 類似於 UITableView所使用的數據源。不像蘋果的照片 應用程序,它不侷限於本地存儲 的照片。您的照片可以從網絡加載 ,並且可以逐步加載長列表 照片。

0

工作對我來說更好(丹尼爾的代碼修改):

UIScrollView *s = [[UIScrollView alloc] initWithFrame:someFrame]; 
int numOfColumns = 4; 
int numOfRows = imagesArray.count/numOfColumns+1; 
int space = 10; 
int width = (s.frame.size.width-(numOfColumns+1)*space)/numOfColumns; 
int height = width; 
int x = space; 
int y = space; 
for (int i=1; i<=imagesArray.count; i++) { 
    UIImageView *image= [[UIImageView alloc] initWithFrame:CGRectMake(x,y,width,height)]; 
    image.image = [UIImage imageWithData:[imagesArray objectAtIndex:i-1]]; 
    [s addSubview:image]; 
    [image release]; 
    if (i%numOfColumns == 0) { 
     y += space+height; 
     x = space; 
    } else { 
     x+=space+width; 
    } 
} 
int contentWidth = numOfColumns*(space+width)+space; 
int contentHeight = numOfRows*(space+height)+space; 
[s setContentSize:CGSizeMake(contentWidth, contentHeight)]; 
[self.view addSubview:s]; 

imagesArrayNSData

一個 Array
相關問題