2011-11-15 3 views
0

서버에서 미리보기 이미지 (미리보기 이미지)를로드하고 로컬 문서 디렉토리에 저장하고 있습니다. 각 이미지에는 핵심 데이터 항목이 있습니다.iOS에서 UIButton 행렬을 생성합니다.

이제 Thumbnail을 ScrollView에 렌더링해야합니다. 미래에 얼마나 많은 미리보기 이미지가 있는지, 왜 엄지 손가락을 프로그래밍 방식으로 ScrollView에 렌더링해야하는지 모릅니다. 스크롤 썸네일의 수에 따라 scrollView의 높이를 설정해야한다는 것도 알고 있습니다.

썸네일을 터치 할 필요가 있습니다. 미리보기 이미지를 탭하면 다른 대화가 열립니다.

첫 번째 질문 : 미리보기 이미지를 표시하는 데 사용할 올바른 컨트롤은 무엇입니까? 축소판이 배경 이미지로 설정된 사용자 지정 단추로 UIButton입니까?

두 번째 질문 : 어떻게하면 엄지 손가락 (버튼)을 렌더링 할 수있는 동적 매트릭스를 설정할 수 있습니까?

감사

답변

1

먼저 답 : 나는 이것이 내가이 상황에서 어떻게 할 것인지이다이 목적을 위해 UIButton 사용하는 것이 좋습니다 것입니다

두 번째 대답 : 당신은 모든 어떤 종류의 배열을 가정하여

NSArray *thumbnailImages; 
UIScrollView *scrollView; 
//Scrollview is linked up through IB or created dynamically...whatever is easier for you 
//The thumbnailImages array is populated by your list of thumbnails 

//Assuming that your thumbnails are all the same size: 
const float thumbWidth = 60.f;//Just a random number for example's sake 
const float thumbHeight = 90.f; 
//Determine how many thumbnails per row are in your matrix. 
//I use 320.f as it is the default width of the view, use the width of your view if it is not fullscreen 
const int matrixWidth = 320.f/thumbWidth; 

const int contentHeight = thumbHeight * (thumbnailImages.count/matrixWidth); 

for (int i = 0; i < thumbnailImages.count; ++i) 
{ 

    int columnIndex = i % matrixWidth; 
    int rowIndex = i/matrixWidth;//Intentionally integer math 

    UIImage* thumbImage = [thumbnailImages objectAtIndex:i]; 
    UIButton* thumbButton = [[UIButton alloc] initWithFrame:CGRectMake(columnIndex*thumbWidth, rowIndex*thumbHeight, thumbWidth, thumbHeight)]; 

    thumbButton.imageView.image = thumbImage; 

    [scrollView addSubView:thumbButton]; 

    [thumbButton release]; 
} 

[scrollView setContentSize: CGSizeMake(320.f, contentHeight)]; 
반드시 코드로 단어를이 말을 오해하지 마세요, 난 그냥 메모장에서이 쓴

:하지만, 썸네일, 당신은 단순히이 유사한 방식으로 모든 버튼을 만들려면 어떻게해야합니까 반복 할 수 있습니다 그것은 당신에게 g를 주어야합니다. 그것을하는 방법의 eneral 아이디어

+0

좋아,이 작품. 하지만 UIButton을 사용할 수 없게하는 한 가지 요구 사항을 발견했습니다. 사용자가 더 긴 시간 동안 축소판에 손가락을 가볍게 두드리면 축소판과 기본 코어 데이터 및 문서 디렉토리의 데이터를 삭제할 수 있어야합니다. 그거 알아? – MadMaxAPP

+0

흠, 확실하지 않습니다. 어떤 종류의 파악 제 인식기가있는 경우 iOS에서 이러한 종류의 것들이 정상적으로 처리되는 방법을 알지 못합니다. UIButton 클래스 레퍼런스를 확인하려면 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html을 참조하고 이벤트 또는 셀렉터의 종류가 있는지 확인해야합니다. 필요한 것. –

+0

UIImageView를 사용하는 사용자 정의 뷰를 만들 수도 있고 UIButton을 하위 클래스 UIDutton으로 만들 수도 있습니다. 그러나 매트릭스를 설정하는 방법에 대한 일반적인 아이디어는 위에서 설명한 방법과 같습니다. –