2016-08-26 6 views
0

제 질문은 매우 간단합니다. UITableView에서 이와 같은 구분 기호를 구현하는 방법입니다.UITableView : 사용자 정의 구분자

enter image description here

는이 코드

let screenWidth = UIScreen.mainScreen().bounds.width 
let path = UIBezierPath(); path.lineWidth = 0.2 
path.moveToPoint(CGPointMake(10, cell.height)) 
path.addLineToPoint(CGPointMake(screenWidth - 20, cell.height)) 
let shapeLayer:CAShapeLayer = CAShapeLayer() 
shapeLayer.strokeColor = UIColor.blackColor().colorWithAlphaComponent(0.3).CGColor 
shapeLayer.fillColor = nil 
shapeLayer.lineDashPattern = [1,3] 
shapeLayer.path = path.CGPath 
cell.layer.addSublayer(shapeLayer) 

에 의해 Cell.layer에 점선을 포함 CAShapeLayer를 추가하려고하는 데 사용하지만 자체 크기 테이블 뷰 셀과 작동하지 않았다

tableView.rowHeight = UITableViewAutomaticDimension

귀하의 도움에 감사드립니다!

+0

의 사용 가능한 복제 [jQuery과 구분 라인 (http://stackoverflow.com/questions/4804632/uitableview-separator-line) –

답변

0

당신은 점선이있는 image으로 이것을 달성 할 수 있습니다. 이 시도 :

self.tableView.separatorColor = UIColor(patternImage: UIImage(named: "YourDottedImage")!) 
+0

내일, tUITableViewCellSeparatorStyle의 서브 클래스를 만들고 뭔가 재미있는 일을하면 어떨까요 :) –

+0

'UITableViewCellSeparatorStyle'을 서브 클래스화할 수 있습니까? – Santosh

+0

솔직히 말해서 나는 불가능하다고 생각합니다 :)) 그러나 우리는 확장 또는 다른 방법으로 전 확장 할 수 있습니다. –

0

당신은 라인 위쪽으로 이동을 시도 할 수

path.moveToPoint(CGPointMake(10, cell.height-1)) 
path.addLineToPoint(CGPointMake(screenWidth - 20, cell.height-1)) 
관련 문제