ios - Rounded rect using UIRectCorner in Swift not working -
i trying create rounded rect uitableviewcell have created in storyboard. using swift 2 in xcode 7. have 2 views in prototype cell, topview , bottom view. want topview have top corners rounds, , bottomview have corners rounded.
in awakefromnib (may go somewhere else better later):
... self.topview.backgroundcolor = uicolor.redcolor() self.bottomview.backgroundcolor = uicolor.graycolor() self.setmasktoview(self.topview, corners:uirectcorner.topleft.union(uirectcorner.topright)) self.setmasktoview(self.bottomview, corners: uirectcorner.bottomleft.union(uirectcorner.bottomright)) ...
in separate function (based on answer stack overflow post):
func setmasktoview(view : uiview, corners: uirectcorner) { let rounded = uibezierpath(roundedrect: self.bounds, byroundingcorners: corners, cornerradii: cgsize(width: 10, height: 10)) let mask = cashapelayer() mask.path = rounded.cgpath view.layer.mask = mask }
note, tried [.topright, .topleft] instead of union(), based on various other stack overflow posts. nothing seems change anything. cleaned , restarted xcode in desperation. getting:
if has ideas might up, appreciate it.
thanks.
you have 2 problems.
awakefromnib
based on view bounds, because views haven't been resized device @ point. should create mask layers inawakefromnib
, should set paths inlayoutsubviews
.in
setmasktoview(_:corners:)
, need useview.bounds
, notself.bounds
, create path.
Comments
Post a Comment