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:

top cell shows issue.  .topleft seems applied, though called on 2 separate views

if has ideas might up, appreciate it.

thanks.

you have 2 problems.

  1. awakefromnib based on view bounds, because views haven't been resized device @ point. should create mask layers in awakefromnib, should set paths in layoutsubviews.

  2. in setmasktoview(_:corners:), need use view.bounds, not self.bounds, create path.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -