UISB ScrollView

 

viewcontroller.m

 

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //定义并且创建一个滚动视图
    //可以对视图内容进行滚屏查看功能
    
    UIScrollView* sv =[[UIScrollView alloc]init];
    //设置滚动视图位置 使用矩形来定位视图位置
    
    sv.frame=CGRectMake(0, 0, 320, 576);
    //是否按照首页来滚动视图
    
    sv.pagingEnabled=YES;
    //是否可以开启滚动效果
    
    sv.scrollEnabled=YES;
    //画布大小 画布显示在滚动视图内部 一般大于frame
    sv.contentSize=CGSizeMake(320*2, 576);
    //是否可以边缘弹动效果
    sv.bounces=YES;
    //开启横向弹动效果
    sv.alwaysBounceHorizontal=YES;
    //开启纵向弹动效果
    sv.alwaysBounceVertical=YES;
    
    //展示横向弹动效果
    sv.showsHorizontalScrollIndicator=YES;
    //展示纵向弹动效果
    sv.showsVerticalScrollIndicator=YES;
    sv.backgroundColor=[UIColor yellowColor];
    
    //使用循环创建5张图片视图
    for( int i=0 ; i<5 ;i++)
    {
        NSString* strName = [NSString stringWithFormat:@"%d.jpg",i+1];
        UIImage* image =[UIImage imageNamed:strName];
        UIImageView* iview=[[UIImageView alloc]initWithImage:image];
        
        iview.frame=CGRectMake(320*i, 0, 320, 576);
        [sv addSubview:sv];
        
        
    }
    
    
    
    [self.view addSubview:sv];
    
    
    
    
    
}


@end

 

posted @ 2020-09-16 23:09  逆欢  阅读(147)  评论(0编辑  收藏  举报