2013-04-19 3 views
1

Xcode 4.6에서 UIScrollview를 사용하고 있습니다. scrollview에 약 30 개의 이미지를 삽입하고 싶습니다. 스토리 보드 내에서는 실제로 스토리 보드를 아래로 스크롤하여 더 많은 이미지를 추가 할 수 없으므로이 부분을 추가 할 수 없으므로 모든 이미지가 서로 겹칩니다.많은 이미지가 포함 된 UIScrollview

답변이 매우 간단하므로 현혹되지 않는 경우 미안합니다. 이 많은 이미지를 scrollview에 추가하려면 어떻게해야합니까? 안드로이드 XML과 같은 코드를 작성할 수있는 방법이 있습니까? 아니면 어쨌든 이미지가 겹치지 않도록 할 것입니까?

+1

스크롤보기의 콘텐츠 크기를주의 깊게 살펴보십시오. 콘텐츠 크기가 모든 이미지 높이의 합계와 같거나 커야합니다. – NULL

답변

2

또한 UITableView 사용을 고려하십시오. 많은 이미지를 처리하는보다 효율적인 방법 일 수 있습니다. 한꺼번에 표시되는 것이 아니라 표시되는대로로드 할 수 있습니다.

1

인터페이스 빌더에서이 작업을 수행하고 싶지는 않습니다. 그러면 작성 및 유지 관리의 악몽이됩니다.

대신 코드에서 수행하십시오. 시작하려면 Google UIScrollView tutorial으로 보내주세요. 이미지 뷰를 손으로 드래그하는 것보다 훨씬 쉽습니다.

1

그래서 전에 풀었던 문제입니다. 이 문제를 해결할 수있는 몇 가지 방법이 있습니다. 적어도 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]; 



} 

여기에없는 다른 많은 코드가 있지만 여기에 페이지 레이아웃이 처리됩니다. 심지어 이것이 최적의 해결책은 아니지만 잘하면 도움이 될 것입니다.

행운을 빈다.^_^

관련 문제