ios - Objects cleared when adding subLayer to UIView -
i'm have using custom uiview
class, has textfields , labels contained within it, courtesy of storyboard. when class adds sublayer within class, contained objects on view disappear, made transparent or maybe become same color of uiview
background. there property can set or method employ ensure objects remain visible?
thanks in advance!
here code:
class viewborder: uiview { override init(frame: cgrect) { super.init(frame: frame) } required init?(coder adecoder: nscoder) { super.init(coder: adecoder) } override func drawrect(rect: cgrect) { super.drawrect(rect) // create rect 1x rounded corner let rectpath = uibezierpath(roundedrect: bounds, byroundingcorners: uirectcorner.topleft, cornerradii: cgsize(width: 21.0, height: 21.0)) let rectlayer = cashapelayer() rectlayer.shadowoffset = cgsize(width: -1.5, height: -1.5) rectlayer.shadowopacity = 0.6 rectlayer.path = rectpath.cgpath rectlayer.fillcolor = tintcolor.cgcolor self.layer.addsublayer(rectlayer) } }
try this:
override func drawrect(rect: cgrect) { super.drawrect(rect) // create rect 1x rounded corner let rectpath = uibezierpath(roundedrect: bounds, byroundingcorners: uirectcorner.topleft, cornerradii: cgsize(width: 21.0, height: 21.0)) let rectlayer = cashapelayer() rectlayer.shadowoffset = cgsize(width: -1.5, height: -1.5) rectlayer.shadowopacity = 0.6 rectlayer.path = rectpath.cgpath rectlayer.fillcolor = tintcolor.cgcolor rectlayer.zposition = -1 // added self.layer.addsublayer(rectlayer) }
Comments
Post a Comment