ios - Setting mask layer on UITableViewCell's subview overrides Auto Layout constraints -


i have uitableviewcell multiple subviews. 1 of subviews uilabel , cell's height dynamically sized based on amount of text in uilabel. works perfectly.

i have subview in cell has constraints well. subview supposed have exact same height cell. works well.

however, run problems when trying set mask layer on subview. mask layer works correctly, subview's height wrong , not same height cell.

here mask layer code:

uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:self.mysubview.bounds                                               byroundingcorners:(uirectcornertopleft | uirectcornertopright | uirectcornerbottomleft | uirectcornerbottomright)                                                     cornerradii:cgsizemake(10, 10)];  cashapelayer *masklayer = [cashapelayer layer]; masklayer.frame = self.mysubview.bounds; masklayer.path = maskpath.cgpath; self.mysubview.layer.mask = masklayer; 

i have been doing research , trying find way fix can both set mask layer , have subview have it's correct height haven't been able work.

i have seen solution recommended several times now:

[self setneedlayout]; [self layoutifneeded]; // customize cell after here 

but doesn't work me either. there way me know when auto layout constraints have been applied can apply mask layer afterwards?

the mask layer code simple, uses bounds of subview, , bounds off because it's using bounds exist before constraints have been applied , subview has correct height. @ least think i'm understanding correctly.

i got it. i'm not sure if correct place put or if might cause performance problems, far works perfectly:

- (void)drawrect:(cgrect)rect {   [super drawrect:rect];    uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:self.mysubview.bounds                                                byroundingcorners:(uirectcornertopleft | uirectcornertopright | uirectcornerbottomleft | uirectcornerbottomright)                                                      cornerradii:cgsizemake(10, 10)];    cashapelayer *masklayer = [cashapelayer layer];   masklayer.frame = self.mysubview.bounds;   masklayer.path = maskpath.cgpath;   self.mysubview.layer.mask = masklayer;  } 

i had override drawrect: in uitableviewcell subclass , set mask layer there.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -