ios - How to stroke a grid of points relative to UIView size? -
i'm trying stroke array of uibezierpath
point grid on display. spacing of points relative size of uiview
, like: (bounds.uiview / 10)
make spacing 10 on each side
so have 2 questions:
1) how stroke single point using uibezierpath
?
2) how create array of points , stroke them on uiview
.
here example in swift 3:
func adddashedline(layer: calayer, dotsize: cgfloat) { let p0 = cgpoint(x: 0, y: layer.bounds.height/2) let p1 = cgpoint(x: layer.bounds.width, y: layer.bounds.height/2) let path = uibezierpath() path.move(to:p0) path.addline(to:p1) path.stroke() let steplength = float(layer.bounds.width/10.0) let dashpattern = [nsnumber(value: 0.001), nsnumber(value: steplength)] let shapelayer = cashapelayer() shapelayer.frame = layer.bounds shapelayer.strokecolor = uicolor.red.cgcolor shapelayer.linewidth = dotsize shapelayer.linejoin = kcalinejoinround shapelayer.linecap = kcalinecapround shapelayer.linedashpattern = dashpattern shapelayer.linedashphase = dotsize shapelayer.path = path.cgpath layer.addsublayer(shapelayer) }
this example uses simple path draw horizontal line. if need draw line fixed amount of dots, need calculate it's length first , divide number of dots want drawn.
usage:
override func viewdidload() { super.viewdidload() adddashedline(layer: view.layer, dotsize: 3) }
output:
Comments
Post a Comment