ScrollView

헤더파일


@interface ViewController : UIViewController

{

    UIScrollView *scrollView;

    UIView *contentView;

}


메인파일


- (void)viewDidLoad

{

    [super viewDidLoad];

    

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(50, 10, 200, 400)];

    contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 400)];

    

    int total = 0;

    

    for (int i=0; i<5; i++)

    {

        CGRect imageViewFrame;

        imageViewFrame = CGRectMake(total, 0, 200, 400);

        total += 200;

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageViewFrame];

        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", i+1]];

        [imageView setImage:image];

        [contentView addSubview:imageView];

        [imageView release];

    }

    

    [scrollView addSubview:contentView];

    [scrollView setContentSize:contentView.frame.size];

    [scrollView setPagingEnabled:YES];

    [self.view addSubview:scrollView];

}

'Developer > iOS - Objective-C' 카테고리의 다른 글

메모리 해제 (dealloc, release)  (0) 2012.09.11
Progress  (0) 2012.09.11
ScrollView  (0) 2012.09.11
AlertView / ActionSheet 활용  (0) 2012.09.10
Notification 활용  (0) 2012.09.10
UITextField 입력 제한  (0) 2012.09.10

이 글을 공유하기


댓글(0)

Designed by CMSFactory.NET