UIScrollView的简单使用

//

//  ScrollViewController.m

//  MyScrollView

//

//  Created by lanou on 12-12-20.

//  Copyright (c) 2012 lanou. All rights reserved.

//

 

#import "ScrollViewController.h"

 

@interfaceScrollViewController ()

 

@end

 

@implementation ScrollViewController

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    returnself;

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

    UIScrollView *s = [[UIScrollViewalloc]initWithFrame:CGRectMake(100, 100, 120, 200)];

    

    UIImageView *imageView1 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"t1.png"]];

    

    UIImage *image2 = [UIImageimageNamed:@"t2.png"];

    UIImageView *imageView2 = [[UIImageViewalloc]initWithImage:image2];

    imageView2.frame = CGRectMake(imageView1.frame.size.width, 0, image2.size.width, image2.size.height);

    s.contentSize = CGSizeMake(imageView1.frame.size.width+image2.size.width, imageView1.frame.size.height);

    

    s.scrollsToTop = YES;//点下title  ScrollView自动滑

    s.pagingEnabled = YES;//一次滑动一个ScrollView的长或宽

    s.bounces = NO;//边界可超出单自动缩回

    

    [s addSubview:imageView1];

    [s addSubview:imageView2];

    [self.viewaddSubview:s];

}

 

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

posted @ 2012-12-20 13:39  言程序  阅读(159)  评论(0)    收藏  举报