我有一個應用程序,其中我動態,根據該我是從一個array.like此`如何動態設置滾動視圖內容?
for(int i =0;i<[sarray count];i++)
{
NSMutableDictionary *dicttable=[sarray objectAtIndex:i];
NSString *head=[dicttable objectForKey:@"cat"];
btn= [UIButton buttonWithType:UIButtonTypeCustom];
int j=i+1;
btn.frame = CGRectMake((j-1)*87,0,87, 44);
[btn setBackgroundImage:[UIImage imageNamed:@"bar.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"bar_hvr.png"] forState:UIControlStateSelected];
btn.backgroundColor = [UIColor clearColor];
btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
btn.titleLabel.textColor = [UIColor whiteColor];
[btn setTitle:head forState:UIControlStateNormal];
btn.tag = i;
[btn setShowsTouchWhenHighlighted:YES];
[Scroller addSubview:btn];
[btn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
if(btn.tag==0)
{
sendActionsForControlEvents:UIControlEventTouchUpInside];
}
else
{
btn.selected=NO;
}
}
}
[Scroller setContentSize:CGSizeMake([sarray count]*85, 44)];
` 但這裏的問題是創建的按鈕的數量設置滾動視圖的內容大小最後一個按鈕也。它不需要被happend滾動視圖滾動後,我需要用滾動視圖上最後一個按鈕結束後,任何人可以幫助我在此
檢查此:-http://stackoverflow.com/questions/10518790/how-to-set-content-size-of-uiscrollview-dynamically –
chnge以下並檢查。 CGRectMake((j-1)* 87,0,85,44); [Scroller setContentSize:CGSizeMake([sarray count] * 87,44)]; – vamsi575kg
@Gup thats已經工作,但我的問題是,如果它到達第一個按鈕,然後需要停止滾動到右側,如果它到達最後一個按鈕,那麼我需要停止滾動left.thats真正的pbm.in我的情況下,它滾動在這兩種情況下略高一點 – hacker