2016-12-08 5 views
0

UIViewの中央に線を配置したいとします。テーブルビューのセルでUIViewのx位置を確認

the line is not at the centre of my icon

override func draw(_ rect: CGRect) { 
    if let anchor = anchorView(){ 
     print("Anchor x origin : \(anchor.bounds.origin.x)") 
     anchor.backgroundColor = UIColor.blue 
     timeline.start = CGPoint(x: anchor.bounds.origin.x + anchor.frame.width/2 , y: 0) 
     timeline.middle = CGPoint(x: timeline.start.x, y: anchor.frame.origin.y) 
     timeline.end = CGPoint(x: timeline.start.x, y: self.bounds.size.height) 
     timeline.draw(view: self.contentView) 
    }else{ 
     print("this should not happen") 
    } 
} 

私はUIViewののx位置はゼロに等しい

+0

あなたはx poを設定できますyourview.frame.size.origin.x + yourview.frame.size.width/2のような行の区切り –

+0

このエラーが発生しました:「タイプCGSizeの値はメンバー '起点がありません」 –

答えて

1

UIViewfunc convert(_ point: CGPoint, to view: UIView?) -> CGPointは何が必要かもしれません取得しています:

let centerRelativeToTableView = anchor.superview!.convert(anchor.center, to: tableView) 

次にあなたがcenterRelativeToTableView.x

を使用することができます
+0

ありがとうございました。 :) –

関連する問題