i'm trying design scaleable uibezier.
this swift code:
@ibdesignable class animatedringview: uiview { override func draw(_ rect: cgrect) { //// color declarations let strokecolor = uicolor(red: 1.000, green: 0.706, blue: 0.004, alpha: 1.000) //// bezier drawing let bezierpath = uibezierpath() bezierpath.move(to: cgpoint(x: 48.93, y: 266.07)) bezierpath.addcurve(to: cgpoint(x: 48.93, y: 53.93), controlpoint1: cgpoint(x: -9.64, y: 207.49), controlpoint2: cgpoint(x: -9.64, y: 112.51)) bezierpath.addcurve(to: cgpoint(x: 261.07, y: 53.93), controlpoint1: cgpoint(x: 107.51, y: -4.64), controlpoint2: cgpoint(x: 202.49, y: -4.64)) bezierpath.addcurve(to: cgpoint(x: 261.07, y: 266.07), controlpoint1: cgpoint(x: 319.64, y: 112.51), controlpoint2: cgpoint(x: 319.64, y: 207.49)) bezierpath.addline(to: cgpoint(x: 261.07, y: 266.07)) bezierpath.linecapstyle = .round; bezierpath.linejoinstyle = .round; strokecolor.setstroke() bezierpath.linewidth = 10 bezierpath.stroke() } } this result:
my problem: save time, created uibezierpath paintcode:
and can see above, have width , height uibezierpath, however, code displayed points of uibezierpath ...
how can create size variable assign value via code (or inspector) automatically identify points of uibezierpath?
is possible? need help!
given creating circular arc, using bezier curves purpose seems overkill.
with uibezierpath, can use function:
func addarcwithcenter(_ center: cgpoint, radius radius: cgfloat, startangle startangle: cgfloat, endangle endangle: cgfloat, clockwise clockwise: bool)
and set radius, along requisite start , end angles.
if must use cubic béziers purpose, should use magic number kappa equals 0.5522847498, , control points circle built out of cubic béziers.
i have placed small demo of i'm describing on web site at:
http://www.trilithon.com/download/animatedringview.zip
hope helps.


Comments
Post a Comment