2014-02-18 86 views
4

我想爲我的UITableViewCell添加虛線底部邊框。爲UITableViewCell繪製虛線邊框底部

目前,我使用下面的代碼,

CAShapeLayer *border = [CAShapeLayer layer]; 
    border.strokeColor = [UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor; 
    border.fillColor = nil; 
    border.lineDashPattern = @[@1, @1]; 
    border.path = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath; 
    border.frame = CGRectMake(cell.bounds.origin.x, cell.bounds.origin.y + cell.bounds.size.height, cell.bounds.size.width, 1); 
    [cell.layer addSublayer:border]; 

有了這個代碼,我有一個虛線邊框底部爲我的手機,但虛線邊框的高度是兩個時間太大。

但我不是很好操縱CAShapeLayer,我沒有找到任何幫助我的東西。

謝謝!

+0

你把這段代碼放在哪裏? – Alper

回答

4

如果這個筆畫太寬,請嘗試更改圖層的lineWidth。這樣的事情會做的伎倆:

border.lineWidth = 1./[[UIScreen mainScreen] scale]; 

這將繪製在非視網膜設備1px的線,並在視網膜那些1px的線(0.5pt),導致超清晰的線。

另外,你可以只用一條線而不是在UIBezierPath使用moveToPointaddLineToPoint一個矩形構建路徑:

UIBezierPath *bPath = [UIBezierPath new]; 
[bPath moveToPoint:CGPointZero]; 
[bPath addLineToPoint:(CGPoint){100, 0}]; 
border.path = bPath.CGPath; 

根據需要調整。

0

創建自定義單元格,並設置你的邊界,以自定義單元格

/* drow line bottom */ 
cell.layer.shadowColor = [UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor; 
cell.layer.shadowOpacity = 1.0; 
cell.layer.shadowRadius = 0; 
cell.layer.shadowOffset = CGSizeMake(0.0, 1.0); 

或..底部

其他明智的檢查,他們給的答案來設置波紋管連接電池波紋圖像 UITableView Cells separated by dotted lines

+0

你能向我解釋你怎麼想這樣做?我剛剛編輯了我的第一篇文章。 –

+0

http://www.appcoda.com/customize-table-view-cells-for-uitableview/詳細介紹瞭如何在ios中創建自定義單元格,並且如上所述,您正在創建與創建自定義單元格相同的虛線底部 –