2013-12-23 47 views
0

我有一個圖像數組,它們正在UIScrollView中顯示。如果數組包含5個圖像,則3張圖像應位於第一行,其餘2應移至下一行,所以我只需要連續3張圖像。查看圖像網格

如果我有一個字符串,我會在循環中使用\n,但我有一個對象數組。

+5

使用集合視圖 – IronManGill

+0

:(但我必須使它沒有收集視圖,任何可能性 – Arun

+0

然後使用tableview,並使其像一個gridview – IronManGill

回答

0

使用此代碼

float xPos = 10.0f; 
float yPos = 10.0f; 
int lineCheck = 0; 

for(int i =0; i<10;i++) 
{ 
    if (lineCheck == 3) 
    { 
     lineCheck = 0; 
     xPos = 10.0f; 
    } 
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPos, yPos, 100.0f, 100.0f)]; 
    imgView.image = [UIImage imageNamed:@"YOur image name"]; 
    [scrollView addSubview:imgView]; 

    xPos = xPos+110.0f; 
    yPos = yPos+110.0f; 
    lineCheck = lineCheck+1; 

} 
+0

您的代碼是輝煌的,謝謝很多兄弟。 – Arun

0

可以Customize Table Cells和dsiplay的圖像作爲你的願望。

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     // allocate the cell: 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

     //set conditions,create yourImageView's and desired frames for image view. 

     [cell.contentView addSubview:yourImageView]; 
0

我知道這是非常古老的,但它已經由我在幾個項目中實施。我發現GMGridView是您的案例中最好的解決方案之一。剛檢查出來:

  1. GMGridView
  2. DTGridView
  3. AQGridView

希望你將能夠輕鬆地實現它。