objective c - Scrollable calender month view: title text of custom button in collection view gets overwritten -
i want create custom, scrollable month view, in user able scroll through months of corresponding year (just ipad calendar).
so created 1 array date components need. there 12 subarrays in array, 1 each month. managed fill subarrays right date components of corresponding year.
i set number of sections in collectionview 12 (one each month) , items in section have same number number of days in current month.
in order label button titles within collection view cell date components, wrote method string title label:
- (nsstring *)getdayofmonthfromcomponent: (nsdatecomponents *)components{ nscalendar *gregorian = [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar]; nsdate *newdate = [gregorian datebyaddingcomponents:components todate:self.currentdate options:0]; nsdateformatter *dateformatterdayofmonth = [[nsdateformatter alloc]init]; [dateformatterdayofmonth setdateformat:@"d"]; // filter day of month nsstring *dayofmonth = [dateformatterdayofmonth stringfromdate:newdate]; homecoming dayofmonth; }
that's how label custom button:
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { emmonthcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"monthcell" forindexpath:indexpath]; emborderlessbutton *button; #pragma mark - datelabel sort algorithm iphone if (is_iphone){ #pragma mark - datelabel sort algorithm ipad } else if (is_ipad){ button = [[emborderlessbutton alloc]initwithframe:cgrectmake(110, 10, 30, 30)]; nsstring *titletext; nslog(@"index path: %ld of section: %ld", (long)indexpath.row, (long)indexpath.section); if (indexpath.row < [[self.daysthismontharray objectatindex:indexpath.section] intvalue]){ titletext = [self getdayofmonthfromcomponent:self.datecomponents [indexpath.section] [indexpath.row]]; } [button settitle:titletext forstate:uicontrolstatenormal]; [button setuserinteractionenabled:no]; [button setselected:false]; [button settag:indexpath.row]; [cell addsubview:button]; [self.buttonarray addobject:button]; [cell bringsubviewtofront:button]; } homecoming cell; }
the labeling basicly works, start scrolling, titlelabels overwritten. how can solve issue? in advance help.
solved it. solution pretty simple: interface builder dragged button in collection view cell , assigned custom button class. addition, connected created button outlet custom collection view cell class.
afterwards changed code this:
#pragma mark - datelabel sort algorithm ipad } else if (is_ipad){ nslog(@"check content: %@", self.daysthismontharray); emborderlessbutton *thelabel = (emborderlessbutton *)[cell viewwithtag:100]; [thelabel settitlecolor:[uicolor em_darkviolett] forstate:uicontrolstatenormal]; if (indexpath.row < [[self.daysthismontharray objectatindex:indexpath.section] intvalue]){ [cell.datebutton settitle:[self getdayofmonthfromcomponent:self.datecomponents [indexpath.section] [indexpath.row]] forstate:uicontrolstatenormal]; if ([[self getdayofmonthfromcomponent:self.datecomponents [indexpath.section] [indexpath.row]] isequaltostring:@"1"]){ [cell.datebutton settitle:[nsstring stringwithformat:@"%@. %@", [self getdayofmonthfromcomponent:self.datecomponents [indexpath.section] [indexpath.row]], [self getmonthnamefromcomponents:self.datecomponents [indexpath.section] [indexpath.row]]] forstate:uicontrolstatenormal]; } } [self.buttonarray addobject:thelabel]; } homecoming cell; }
objective-c calendar uicollectionview
No comments:
Post a Comment