2013-04-16 3 views
0

내보기에서 가로 ScrollView가 필요합니다. 배열에 단어가 몇 개 있습니다. 그런 다음 ScrollView에서 해당 단어를 표시하고 싶습니다. 어떻게해야합니까?레이블 수가있는 가로 ScrollView

미리 감사드립니다.

답변

0

당신은 다음 코드를 참조 할 수 있습니다 :

for (NSString *text in labelArray) 
{ 
    label = [[UILabel alloc] initWithFrame:CGRectMake(scrollWidth,12,132,140)]; 
    imageView.backgroundColor=[UIColor whiteColor]; 
    scrollWidth +=165; 
    label.text=text; 
    [bookScroll addSubview:label]; 
} 

귀하의 요구 사항에 따라 라벨의 스크롤 폭과 범위를 조정합니다.

0

당신이

CGRect labelFrame = CGRectMake(0.0f, 0.0f, scrollView.frame.size.width, scrollView.frame.size.height); 
    for (NSString *text in wordsArray) { 
     UILabel *label = [[UILabel alloc]initWithFrame:labelFrame]; 
     label.text = text; 
     [scrollView addSubview:label]; 

     labelFrame.origin.x +=labelFrame.size.width; 
    } 

    CGSize contentSize = scrollView.frame.size; 
    contentSize.width = labelFrame.origin.x; 
    scrollView.contentSize = contentSize; 
+0

하지만 그 단어 하나만 인쇄해도 배열에 5 단어가 있습니다. – username0013

+0

@SwethaReddy scrollView와 동일한 레이블의 너비를 부여 했으므로 하나의 레이블 만 표시됩니다. labelFrame의 너비를 수정하고 제대로 작동하는지 확인할 수 있습니다. 그 사이에 다른 레이블을 스크롤하고 볼 수 있습니까? – Anupdas

+0

나는 그 문자열을 어떻게 표시 할 것인가, scrollview에 문자열을 두는 방법을 모르겠다. – username0013

0
int pos = 5; 
for (int i=0; i<[yourArray count]; i++) 
    { 
     UILabel *lbl = [[UIImageView alloc]init]; 
     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
     { 
      [lbl setFrame:CGRectMake(pos, 0, 300, 440)]; 
      [_scrollView setContentSize:CGSizeMake([yourArray count]*320, 440)]; 
      pos = pos + 320; 
     } 
     else 
     { 
      [lbl setFrame:CGRectMake(pos, 0, 748, 1004)]; 
      [_scrollView setContentSize:CGSizeMake([yourArray count]*768, 1004)]; 
      pos = pos + 768; 
     }   
     lbl.text = [[yourArray objectAtIndex:i]valueForKey:@"text"]]; 
     [_scrollView addSubview:lbl]; 
    } 
0

는 코드 수정의 일부, EasyTableView에서보세요처럼 뭔가를 할 수 있습니다, 당신은 당신이 원하는 것을 얻을 수 있습니다. 또한, 그 프로젝트에서 배울 것이 많습니다.

적어도 살펴 봅니다.

관련 문제