1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 //滾動視圖,能夠對屏幕內容進行滾屏查看。 4 5 UIScrollView* sv = [[UIScrollView alloc]init]; 6 7 sv.frame = CGRectMake(0, 0, 320, 576); 8 //設置背景顏色 9 sv.backgroundColor = [UIColor orangeColor]; 10 11 //設置畫布的大小,畫布顯示在滾動視圖內部,通常大於frame的大小。 12 sv.contentSize = CGSizeMake(320,576*5); 13 // 是否按照整頁來滾動 14 sv.pagingEnabled = YES; 15 // 是否能夠開啓滾動效果 16 sv.scrollEnabled = YES; 17 18 //是否能夠邊緣彈動效果 19 sv.bounces = YES; 20 //開啓橫向彈動效果 21 sv.alwaysBounceHorizontal = YES; 22 //開啓縱向彈動效果 23 sv.alwaysBounceVertical = YES; 24 //顯示橫向滾動條 25 sv.showsHorizontalScrollIndicator = YES; 26 //顯示縱向滾動條 27 sv.showsVerticalScrollIndicator = YES; 28 29 for(int i=0;i<2;i++) 30 { 31 NSString* strName = [NSString stringWithFormat:@"%d.jpg",i+1]; 32 UIImage* image = [UIImage imageNamed:strName]; 33 34 UIImageView* iView = [[UIImageView alloc] initWithImage:image]; 35 36 iView.frame = CGRectMake(0, 576*i, 320, 576); 37 38 [sv addSubview:iView]; 39 40 } 41 42 [self.view addSubview:sv]; 43 44 }