美文网首页
iOS UIScrollView卡片滑动

iOS UIScrollView卡片滑动

作者: 江河_ios | 来源:发表于2018-01-23 17:57 被阅读0次

很早以前都做过这个效果,之前一直都没有写过东西,今天看到就写了一个......

-(UIScrollView *)scrollView

{

    if (!_scrollView) {

        _scrollView=[[UIScrollView alloc]init];

        _scrollView.frame=CGRectMake(50, 200, YHScreenWith-100, 300);

        _scrollView.delegate=self;

        //    _scrollView.showsVerticalScrollIndicator=NO;

        _scrollView.backgroundColor=[UIColor clearColor];

        _scrollView.clipsToBounds = NO;

 self.view.clipsToBounds = YES;

        NSArray *imageArray = @[@"1",@"2",@"3",@"4",@"5",@"6"]; //图片内容

        //

        for (NSInteger i = 0; I < imageArray.count; i ++) {

UIView *view = [[UIView alloc] initWithFrame:CGRectMake((YHScreenWith -100) *i, 0, YHScreenWith -100, 300)];

            view.backgroundColor = [UIColor clearColor];

            [self.scrollView addSubview:view];

            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, view.width -20, 300)];

            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageArray[i]]];

            [view addSubview:imageView];

        }

        _scrollView.contentSize = CGSizeMake((YHScreenWith -100) *6, 300);

        _scrollView.pagingEnabled = YES;

        _scrollView.contentOffset = CGPointMake((YHScreenWith -100) *1, 0);

[self.view addSubview:self.scrollView];

    }

    return _scrollView;

}

效果图

相关文章

网友评论

      本文标题:iOS UIScrollView卡片滑动

      本文链接:https://www.haomeiwen.com/subject/pvxeaxtx.html