그래서 전에 풀었던 문제입니다. 이 문제를 해결할 수있는 몇 가지 방법이 있습니다. 적어도 iOS 6.x에서는 UICollectionView를 사용하도록 선택할 수있는 새로운 우선적 인 방법이라고 생각합니다.
UICollectionView View Apple Docs
이 도움이되는 정보의 부하를 가지고 훌륭한 튜토리얼 사이트입니다
UICollectionView Tutorial
또한 내가로드 수동으로 이미지를 배치했다 해낸 하나 개의 솔루션. 그리고 나서 너비가 필요한 크기를 기반으로 UIScrollView setcontentSize 속성을 설정했습니다.
//Clean Up and remove old buttons
for(int i=0; i < _localButtonArray.count; i++){
[(CategoryButton*)[_localButtonArray objectAtIndex:i] removeFromSuperview];
}
[_localButtonArray removeAllObjects];
CGFloat baseX = 10,
X = 0,
Y = 0;
int xPadding = 20,
yPadding = 12,
index = 0,
maxRow = 4,
maxCol = 4,
colCount = 0;
CGRect buttonFrame;
buttonFrame.size.height = 137;
buttonFrame.size.width = 137;
buttonFrame.origin.y = X;
buttonFrame.origin.x = Y;
for(int i = 0;i < _localInfoArray.count ; i++){
id object = [_localInfoArray objectAtIndex:i];
if(index >= maxRow){
index = 0;
X = baseX;
Y += buttonFrame.size.height + yPadding;
if(colCount >= (maxRow * maxCol)){
colCount=0;
baseX += 637;
Y = 0;
}
}
X = baseX + (index * (buttonFrame.size.width + xPadding));
index++;
colCount++;
buttonFrame.origin.x = X;
buttonFrame.origin.y = Y + yPadding;
/*
* Custom button class
*/
CategoryButton * categoryButton = [[CategoryButton alloc]initWithFrame:buttonFrame Object:object];
//Add action
[categoryButton addTarget:self action:@selector(categoryButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[categoryButton.titleLabel setNumberOfLines:3];
[categoryButton.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
[categoryButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:19]];
[categoryButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
[categoryButton setMultipleTouchEnabled:NO];
[_localButtonArray addObject:categoryButton];
[self.view addSubview:categoryButton];
}
여기에없는 다른 많은 코드가 있지만 여기에 페이지 레이아웃이 처리됩니다. 심지어 이것이 최적의 해결책은 아니지만 잘하면 도움이 될 것입니다.
행운을 빈다.^_^
스크롤보기의 콘텐츠 크기를주의 깊게 살펴보십시오. 콘텐츠 크기가 모든 이미지 높이의 합계와 같거나 커야합니다. – NULL