ios - Adding views in the negative way of a uiscrollview and changing contentsize -


i have uiscrollview calendarview in it. want 2 next months , 2 previous months loaded inside scroll view.

i have 2 following methods.

-(void)addcalendartoend{     iphonemonthview *phonecal =  [[iphonemonthview alloc] init];     phonecal.delegate = self;     phonecal.datasource = self;     [phonecal selectdate:[self samedatebyaddingmonths:1 anddate:scrolldate]];     float xvalue = phonecal.frame.size.width * numberofcalendarsaftertoday;     phonecal.frame = cgrectmake(xvalue, 0, phonecal.frame.size.width, phonecal.frame.size.height);     [self.calendarscroll addsubview:phonecal];     int numberscroll = numberofcalendarsbeforetoday + numberofcalendarsaftertoday + 1;     calendarscroll.contentsize = cgsizemake(numberscroll*phonecal.bounds.size.width,calendarscroll.bounds.size.height);     [calendarscroll addsubview:phonecal];     nslog(@"content size %f",calendarscroll.contentsize.width);      numberofcalendarsaftertoday++;  } -(void)addcalendertobeginning{     iphonemonthview *phonecal =  [[iphonemonthview alloc] init];     phonecal.delegate = self;     phonecal.datasource = self;     [phonecal selectdate:[self samedatebyaddingmonths:-1 anddate:scrolldate]];     float xvalue = phonecal.frame.size.width * numberofcalendarsbeforetoday;     nslog(@"xvalue %f",xvalue);     phonecal.frame = cgrectmake(-xvalue, 0, phonecal.frame.size.width, phonecal.frame.size.height);     [self.calendarscroll addsubview:phonecal];     int numberscroll = numberofcalendarsbeforetoday + numberofcalendarsaftertoday + 1;     calendarscroll.contentsize = cgsizemake(numberscroll*phonecal.bounds.size.width,calendarscroll.bounds.size.height);     nslog(@"content size %f",calendarscroll.contentsize.width);     numberofcalendarsbeforetoday++; } 

the addcalendartoend working should. addcalendartobeginning isn't. adding view on correct place. don't know how should set contentsize of uiscrollview.

can me?

edit

and i'm doing in viewdidload

 scrolldate = [nsdate new];         iphonemonthview *phonecal =  [[iphonemonthview alloc] init];     phonecal.frame = cgrectmake(0, 0, phonecal.frame.size.width, phonecal.frame.size.height);     phonecal.delegate = self;     phonecal.datasource = self;     [phonecal selectdate:[nsdate new]];     nslog(@"phone call height %f",phonecal.frame.size.height);     float xvalue = phonecal.frame.size.width * numberofcalendarsaftertoday;     phonecal.frame = cgrectmake(xvalue, 0, phonecal.frame.size.width, phonecal.frame.size.height);       calendarscroll = [[uiscrollview alloc]initwithframe:cgrectmake(0, 0, phonecal.frame.size.width, phonecal.frame.size.height)];     calendarscroll.delegate = self;     [calendarscroll addsubview:phonecal];     calendarscroll.backgroundcolor = [uicolor clearcolor];     calendarscroll.contentsize =cgsizemake(numberofcalendarsaftertoday*phonecal.frame.size.width,phonecal.frame.size.height);     calendarscroll.contentoffset = cgpointzero;      [self.calendarview addsubview:calendarscroll];     nslog(@"phone call height %f",phonecal.frame.size.height);       numberofcalendarsbeforetoday++;     numberofcalendarsaftertoday++; 

if it's 5 months wish scroll through, suggest populating content in linear fashion , moving content offset appropriately..

so loop through views adding them scrollview , adjusting origin of frame sit flush each other.

then adjust contentoffset

scrollview.contentoffset.x = 3*phonecal.frame.size.width; 

however if want scrollview "infinite" amount should have @ solution dmcircularscrollview


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -