2011-10-30 4 views
0

UIScrollView에 대해 동적으로 하위보기 (페이지)를 만들 수 있는지 궁금합니다. 난 단지 2가 필요합니다 UILabel. 하나는 상단에, 하나는 하단에 있습니다. 가능하다면 누군가가 내게 어떻게 말해 주거나 튜토리얼/비디오를 가르쳐 줄 수 있습니까?동적 uiscrollview 하위보기 만들기

나는 튜토리얼을 사용했고, 나는 아주 좋아졌다. 그러나 하단에는 1 UILabel 만 있습니다. 그 링크는 여기에 있습니다 http://www.iosdevnotes.com/2011/03/uiscrollview-paging/

이것은 대부분의 행동이라고 생각합니다.

_objects = [[NSArray alloc] initWithObjects:@"",@"Does not include today", @"This does include today", @"Does not include today", @"This does include today", @"Includes the weekends!", nil]; 

_detailLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 0.0, 320.0, 460.0)]; 
_detailLabel1.textAlignment = UITextAlignmentCenter; 
_detailLabel1.font = [UIFont boldSystemFontOfSize:15.0]; 
_detailLabel1.textColor=[UIColor whiteColor]; 
_detailLabel1.backgroundColor=[UIColor colorWithWhite:(CGFloat)1 alpha:(CGFloat)0]; 


_detailLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(320.0, 0.0, 320.0, 460.0)]; 
_detailLabel2.textAlignment = UITextAlignmentCenter; 
_detailLabel2.font = [UIFont boldSystemFontOfSize:15.0]; 
_detailLabel2.textColor=[UIColor whiteColor]; 
_detailLabel2.backgroundColor=[UIColor colorWithWhite:(CGFloat)1 alpha:(CGFloat)0]; 


_detailLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(640.0, 0.0, 320.0, 460.0)]; 
_detailLabel3.textAlignment = UITextAlignmentCenter; 
_detailLabel3.font = [UIFont boldSystemFontOfSize:15.0]; 
_detailLabel3.textColor=[UIColor whiteColor]; 
_detailLabel3.backgroundColor=[UIColor colorWithWhite:(CGFloat)1 alpha:(CGFloat)0]; 
// We are going to show all the contents of the _objects array 
// using only these three UILabel instances, making them jump 
// right and left, replacing them as required: 

[scrollView addSubview:_detailLabel1]; 
[scrollView addSubview:_detailLabel2]; 
[scrollView addSubview:_detailLabel3]; 

다른 곳에서는 다른 코드가 있지만 여기에는 그 주요 부분이 있다고 생각합니다.

답변

0

레이블을 직접 scrollview에 추가하는 대신. 하위 뷰를 만든 다음 하위 뷰에 레이블을 추가 한 다음 scrollview에 추가합니다. 그래서 당신의 일을 끝냈습니다.

튜토리얼에서 언급 한 코드를 참조하십시오.

NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil]; 
    for (int i = 0; i < colors.count; i++) { 
     CGRect frame; 
     frame.origin.x = self.scrollView.frame.size.width * i; 
     frame.origin.y = 0; 
     frame.size = self.scrollView.frame.size; 

     UIView *subview = [[UIView alloc] initWithFrame:frame]; 
     subview.backgroundColor = [colors objectAtIndex:i]; 
     [self.scrollView addSubview:subview]; 

_detailLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 0.0, 100.0, 40.0)]; 
_detailLabel1.textAlignment = UITextAlignmentCenter; 
_detailLabel1.font = [UIFont boldSystemFontOfSize:15.0]; 
_detailLabel1.textColor=[UIColor whiteColor]; 
_detailLabel1.backgroundColor=[UIColor colorWithWhite:(CGFloat)1 alpha:(CGFloat)0]; 
[subview addSubview:_detailLabel1]; 

_detailLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 300.0, 100.0, 40.0)]; 
_detailLabel2.textAlignment = UITextAlignmentCenter; 
_detailLabel2.font = [UIFont boldSystemFontOfSize:15.0]; 
_detailLabel2.textColor=[UIColor whiteColor]; 
_detailLabel2.backgroundColor=[UIColor colorWithWhite:(CGFloat)1 alpha:(CGFloat)0]; 
[subview addSubview:_detailLabel2]; 


     [subview release]; 
    }