2012-10-16 99 views
1

我有一個自定義的UITableViewCell。廈門國際銀行的文件看起來是這樣的:與自定義單元格/自定義背景圖像分組的UITableView

enter image description here

細胞可以通過選擇它來打開和關閉。當單元格關閉時,只有標題標籤和頂部背景圖像可見。下面是表視圖看起來像在模擬器上,打開和關閉:

enter image description here enter image description here

我試圖弄清楚如何處理圓角。目前,我檢查,看看是否該小區是第一,最後或中間細胞,並應用口罩:

if (row == 0) 
{ 
    // Create the path (with only the top corners rounded) 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.titleBackgroundImageView.bounds 
                byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) 
                 cornerRadii:CGSizeMake(10.0, 10.0)]; 

    // Create the shape layer and set its path 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    maskLayer.frame = cell.titleBackgroundImageView.bounds; 
    maskLayer.path = maskPath.CGPath; 

    // Set the newly created shape layer as the mask for the image view's layer 
    cell.titleBackgroundImageView.layer.mask = maskLayer; 
    cell.bodyBackgroundImageView.layer.mask = nil; 
} 
else if ((row + 1) == [itemsForSection count]) 
{ 
    // Create the path (with only the bottom corners rounded) 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.titleBackgroundImageView.bounds 
                byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) 
                 cornerRadii:CGSizeMake(10.0, 10.0)]; 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 

    // Create the shape layer and set its path 
    BOOL isOpened = [[[self.cellOpenedStatusMutableDictionary objectForKey:sectionTitle] objectAtIndex:row] boolValue]; 
    if (isOpened) 
    { 
     cell.titleBackgroundImageView.layer.mask = nil; 
    } 
    else 
    { 
     maskLayer.frame = cell.titleBackgroundImageView.bounds; 
     maskLayer.path = maskPath.CGPath;   
     cell.titleBackgroundImageView.layer.mask = maskLayer; 
    } 
     // Create the path (with only the bottom corners rounded) 
    maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bodyBackgroundImageView.bounds 
            byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) 
              cornerRadii:CGSizeMake(10.0, 10.0)]; 

    // Create the shape layer and set its path 
    maskLayer = [CAShapeLayer layer]; 
    maskLayer.frame = cell.titleBackgroundImageView.bounds; 
    maskLayer.path = maskPath.CGPath; 

    cell.bodyBackgroundImageView.layer.mask = maskLayer; 
} 
else 
{ 
    cell.titleBackgroundImageView.layer.mask = nil; 
    cell.bodyBackgroundImageView.layer.mask = nil; 
} 

但正如你所看到的,它不是做爲底電池相當的工作 - 在表格視圖的邊界被遮擋。

我該如何解決這個問題?

回答

1

它看起來像所有你需要的是將表視圖的分隔符樣式設置爲「單行」(UITableViewCellSeparatorStyleSingleLine)而不是「單行蝕刻」。