ios - How to draw at the centre of a subview -
i want draw arrow @ center of subview created
{let arrowview = arrowview() arrowview.frame = cgrect(x: selectbutton.frame.minx, y: selectbutton.frame.maxy, width: selectbutton.frame.width, height: processbutton.frame.miny - selectbutton.frame.maxy) arrowview.backgroundcolor = uicolor.white arrowview.viewwithtag(100) view.addsubview(arrowview) } //these codes in view controller to draw arrow in subview use
let arrowpath = uibezierpath.bezierpathwitharrowfrompoint(startpoint: startpoint, endpoint: endpoint, tailwidth: 4, headwidth: 8, headlength: 6) // error occurs here override func draw(_ rect: cgrect) { let fillcolor = uicolor.white fillcolor.setfill() arrowpath.linewidth = 1.0 let strokecolor = uicolor.blue strokecolor.setstroke() arrowpath.stroke() arrowpath.fill() //these codes in subclass of uiview since want draw arrow @ center of subview, define startpoint , endpoint
private var startpoint: cgpoint { return cgpoint(x: bounds.midx, y: bounds.miny) } private var endpoint: cgpoint { return cgpoint(x: bounds.midx, y: bounds.maxy) } //try find point @ centre of subview however, code not compile , error says:
cannot use instance member 'startpoint' within property initializer; property initializers run before 'self' available
edit: know how bounds of subview created code. try "bounds" variable above error.
arrowpath.center = cgpoint(x:arrowview.frame.size.width/2, y: arrowview.frame.size.height/2) arrowview.addsubview(arrowpath)
Comments
Post a Comment