ios - How to get CAShapeLayer to work with constraints with swift? -


i got in viewdidload

rectshape1 = cashapelayer()  rectshape1.fillcolor = uicolor.bluecolor().cgcolor rectshape1.path = uibezierpath(roundedrect: rectshape1.bounds, byroundingcorners: .bottomleft | .topright, cornerradii: cgsize(width: 20, height: 20)).cgpath redview.layer.addsublayer(rectshape1)   var consttop = nslayoutconstraint(item: redview, attribute: nslayoutattribute.centerx, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.centerx, multiplier: 1, constant: 0) view.addconstraint(consttop)  var consth = nslayoutconstraint(item: redview, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: 50) redview.addconstraint(consth)  var constw = nslayoutconstraint(item: redview, attribute: nslayoutattribute.width, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: 50) redview.addconstraint(constw)  consth = nslayoutconstraint(item: redview, attribute: nslayoutattribute.centery, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.centery, multiplier: 1, constant: 0) view.addconstraint(consth) rectshape1.frame = redview.bounds 

and in didlayoutsubviews

            self.rectshape1.frame = self.redview.bounds 

i have similar stuff gradientlayer , works fine, suggestions?

the problem rectshape1.bounds.size {0,0} @ time create bezier path. remove line create path viewdidload, , move after set frame in viewdidlayoutsubviews,

override func viewdidlayoutsubviews() {         self.rectshape1.frame = self.redview.bounds         rectshape1.path = uibezierpath(roundedrect: rectshape1.bounds, byroundingcorners: .bottomleft | .topright, cornerradii: cgsize(width: 20, height: 20)).cgpath     } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -