2010-09-22 42 views
1

我想在UITableViewCells之間有透明度。單元格之間的空間。UITableViewCells之間的透明度

予用戶自定義創建的細胞和用於設定背景我使用此代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CustomCell = @"CustomBookingCell"; 

    currentBooking = [arrayBookings objectAtIndex:indexPath.row]; 

    CustomBookingCell *cell = (CustomBookingCell *)[tableView dequeueReusableCellWithIdentifier:CustomCell]; 

    if (cell == nil) { 

     UIViewController *c = [[UIViewController alloc] initWithNibName:@"CustomBookingCell" bundle:nil]; 
     cell = (CustomBookingCell *)c.view; 
     [ c release ]; 
    } 



    bookingImage = [[UIImageView alloc] initWithImage: 
        [UIImage imageNamed:currentBooking.imageSource]]; 

    [cell.imageForBooking addSubview:bookingImage]; 
    cell.selectionStyle = UITableViewCellSelectionStyleGray; 
    cell.contentView.backgroundColor = [UIColor clearColor]; 


    UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; 
    UIImage* bgImage = [UIImage imageNamed:@"Background_300_82.png"]; 
    UIColor *bgColor = [[UIColor alloc] initWithPatternImage: bgImage]; 

    backgroundView.backgroundColor = bgColor; 
    cell.backgroundView = backgroundView; 
    cell.label.text = currentBooking.title; 

    [bookingImage release]; 
    [bgColor release]; 
    [backgroundView release]; 


    return cell; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 90; 
} 

單元格的高度高10個像素,所述tableCellBg.png。 我的背景視圖也有一個圖像作爲背景(當然,這個背景應該顯示在單元格之間)。

所以我試着在透明底下添加10個像素到底部的tableCellBg.png來解決這個問題。但細胞之間的空間是黑色的。我看不到我的單元格之間的視圖背景。

我該怎麼辦?我是否必須用tableCellBg.png的高度在cellForRowAtIndexPath中創建一個UIView,然後將Custom UITableViewCell作爲子視圖添加到創建的具有較低高度的UIView中?

還是有更簡單的方法來完成這個?

+0

我試圖創建一個黑色的圖像,然後我增加了canvaz尺寸並添加了10個像素的透明度。但是這種透明度變成黑色,就像UITableViewCell backgroundView不支持透明圖像。 – 2010-09-23 09:38:14

回答

1

我解決它通過其他方法可以將背景圖片添加到的UITableViewCell:

UIImage *image = [UIImage imageNamed:@"ny_bg_event.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
imageView.frame = CGRectMake(0, 0, 300, 84); 
cell.backgroundView = imageView; 
cell.backgroundColor = [UIColor clearColor]; 
[imageView release]; 

[cell setFrame:CGRectMake(0, 0, 300, 84)]; 

cell.contentView.backgroundColor = [UIColor clearColor]; 

而不是創建一個UIView我只是用一個UIImageView代替。

5

您的表格視圖需要清晰的背景顏色。例如

myTableView.backgroundColor = [UIColor clearColor]; 
+1

我只是回答相同的問題,所以我反而投了票。 – Echelon 2010-09-22 15:44:35

+0

對不起,我沒有提到我已經有了這個代碼。 – 2010-09-22 16:47:50

+0

我還能嘗試什麼? – 2010-09-23 08:35:46