ios - UICollectionViewCell adding badge -


i want add badge uicollectionviewcell when user press long click on cell. here code :

- (void)activatedeletionmode:(uilongpressgesturerecognizer *)gesture {     if (gesture.state == uigesturerecognizerstatebegan)     {               nsindexpath *indexpath = [_favoritecollection indexpathforitematpoint:[gesture locationinview:_favoritecollection]];         uicollectionviewcell *cell = [_favoritecollection cellforitematindexpath:indexpath];        //m13badgeview *badgeview = [[m13badgeview alloc] initwithframe:cgrectmake(-12,-12, 24.0, 24.0)];         m13badgeview *badgeview = [[m13badgeview alloc] initwithframe:cgrectmake(200,200, 24.0, 24.0)];         badgeview.text = @"1";         [cell addsubview:badgeview];         [cell bringsubviewtofront:badgeview];      } } 

and how cell after long click : enter image description here

as can seen little red coin in cell badge , it's looking when change frame never change position, example :

//m13badgeview *badgeview = [[m13badgeview alloc] initwithframe:cgrectmake(-12,-12, 24.0, 24.0)]; m13badgeview *badgeview = [[m13badgeview alloc] initwithframe:cgrectmake(200,200, 24.0, 24.0)]; 

also i've tried use [cell bringsubviewtofront:badgeview]; or [_favoritecollection bringsubviewtofront:badgeview]; didn't worked.

**note i'm using this library badge

update thank's luke answer setting masktobounds false badge appear got small issue border of cell shown in badge check : enter image description here

to cause badge displayed correctly have ensure cell not clip contents bounds. therefore need set property clipstobounds false. cause badge rendered outside superviews frame.

after looking in code of used library found out after changing text property of badge method called autosetbadgeframe called. function cause frame changed no respect set frame. change behavior should specify alignment using 2 properties horizontalalignment , verticalalignment. setting frame explicitly cause of sublayers maybe displayed incorrectly. , should add subview cell before setting text. order cause explained autosetbadgeframe have valid superview align to.

regarding border: how specify border?


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -