ios - Sending a subview of a collection view cell to the back stops it from changing backgroundColor -


i have custom uicollectionviewcell , i'm adding subview contentview delete button it's hovering on corner of cell little bit outside bounds (just delete button of app in springboard). works fine when try change subview insetview.backgroundcolor after cell highlighted or selected doesn't change.

in uicollectionviewcell

- (void) layoutsubviews {     [super layoutsubviews];      self.insetview = [[uiview alloc] initwithframe:cgrectinset(self.bounds, self.bounds.size.width/64, self.bounds.size.height/16)];     self.insetview.layer.cornerradius = 6;     self.insetview.layer.maskstobounds = yes;     self.insetview.backgroundcolor = [uicolor colorwithred:65/255.0 green:166/255.0 blue:42/255.0 alpha:1];     [self.contentview addsubview:self.insetview];     [self.contentview sendsubviewtoback:self.insetview];     self.backgroundcolor = [uicolor blackcolor]; } 

in collectionviewcontroller

- (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath {     jamcollectionviewcell *cell = (jamcollectionviewcell*)[collectionview cellforitematindexpath:indexpath];     uiview *v = [[cell.contentview subviews] firstobject];     v.backgroundcolor = [uicolor lightgraycolor]; } 

i tried

- (void)collectionview:(uicollectionview *)collectionview didhighlightitematindexpath:(nsindexpath *)indexpath {   jamcollectionviewcell *cell = (jamcollectionviewcell*)[collectionview cellforitematindexpath:indexpath];      cell.insetview.backgroundcolor = [uicolor lightgraycolor]; } 

and tried combinations i. e. trying subview order , change background color in didhighlightitematindexpath , trying subview property name cell.insetview , change background color in didselectitematindexpath nothing worked.

funny thing if subview cell.insetview not sent of cell.contentview does respond changing background color both ways , anywhere. hence question title.

sorry long question , help.

uicollectionview , uicollectionviewcell have built in state management select , highlight, have no visible response it. might try moving logic uicollectionviewcell subclass, might find have better luck.

if you're loading code nib or storyboard can override awakefromnib create custom background view (or add in storyboard , connect cell via iboutlet). otherwise add wherever creating other views.

then can override setselected: , sethighlighted: (remember call super) in custom subclass adjust colors based on current state. have done number of times implementation selection state, , continues work in ios 9.

code worked poster:

(void)setselected:(bool)selected {     [super setselected:selected];     if (selected) {         self.insetview.backgroundcolor = [uicolor lightgraycolor];     }     else {         self.insetview.backgroundcolor = [uicolor colorwithred:65/255.0 green:166/255.0 blue:42/255.0 alpha:1];     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -