ScrollView的使用

本文主要介紹scrollView的使用,使用scrollView來做一個手機相冊。

內容不多,直接上代碼

#import "RootViewController.h"




#define Kwidth _scrollView.frame.size.width 
#define kHight _scrollView.frame.size.height

@interface RootViewController ()

@property(nonatomic,retain)UIScrollView * scrollView;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(30, 100, 320, 480)];


    self.view.backgroundColor = [UIColor whiteColor];

    _scrollView.backgroundColor = [UIColor greenColor];

    [self.view addSubview:_scrollView];




    _scrollView.contentSize = CGSizeMake(19*Kwidth,kHight);


    for (int i = 0; i<19; i++) {

        NSString *imageName = [NSString stringWithFormat:@"image%d.jpg",i+1];

        UIImage *image = [UIImage imageNamed:imageName];


        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*Kwidth, 0, Kwidth, kHight)];

        imageView.image = image;

        [_scrollView addSubview:imageView];

        [imageView release];
    }


    _scrollView.pagingEnabled = YES;


    [_scrollView release];

    // Do any additional setup after loading the view.
}
發佈了65 篇原創文章 · 獲贊 3 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章