UIScrollView基础用法、属性

2017-10-12  本文已影响0人  李琪_59dc

具体使用:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIScrollView* scrollView = [[UIScrollView alloc]init];
    scrollView.frame = CGRectMake(0, 0, 320, 576);
    
    //是否按照整页来滚动视图
    scrollView.pagingEnabled = YES;
    //是否可以开启滚动效果
    scrollView.scrollEnabled = YES;
    //设置画布大小,画布显示在滚动视图内部,一般大小大于frame的大小
    scrollView.contentSize = CGSizeMake(320*5, 576);

    //是否开启边缘弹动效果
    scrollView.bounces = YES;
    scrollView.alwaysBounceHorizontal = YES;
    scrollView.alwaysBounceVertical = YES;

    //显示横向滚动条
    scrollView.showsHorizontalScrollIndicator = YES;
    //显示纵向滚动条
    scrollView.showsVerticalScrollIndicator = YES;
    
    scrollView.backgroundColor = [UIColor orangeColor];
    //使用循环创建5张滚动视图
    for(int i=0;i<5;i++){
        NSString *strName = [NSString stringWithFormat:@"icon%d",i+1];
        UIImage *image = [UIImage imageNamed:strName];
        //创建图像视图
        UIImageView *iView = [[UIImageView alloc]initWithImage:image];
        //设置图像视图的位置
        iView.frame = CGRectMake(320*i, 0, 320, 576);
        [scrollView addSubview:iView];
    }
    [self.view addSubview:scrollView];
}
上一篇下一篇

猜你喜欢

热点阅读