UI基础 ScrollView轮播图

root m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIScrollView* sv=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
    
    sv.backgroundColor=[UIColor yellowColor];
    [self.view addSubview:sv];
    
    //设置大小 多大才能装下四张图片
    sv.contentSize=CGSizeMake(375*4, 667);
    //把图片装进去
    for(int i=1; i<=4; i++){
        NSString* name =[NSString stringWithFormat:@"%d.jpg",i];
        UIImage *image =[UIImage imageNamed:name];
        UIImageView* imageV=[[UIImageView alloc] initWithFrame:CGRectMake(375*(i-1), 0, 375, 667)];
        
        imageV.image=image;
        [sv addSubview:imageV];
        
        
        //分页显示
        sv.pagingEnabled=YES;
        //是否允许反弹
        sv.bounces=NO;
        // 修改滚动条样式
        sv.indicatorStyle=UIScrollViewIndicatorStyleWhite;
        //隐藏滚动条
        sv.showsHorizontalScrollIndicator=NO;
        sv.showsVerticalScrollIndicator=NO;
        //滑动到指定位置
        sv.contentOffset=CGPointMake(375, 0);
        
        
        
    }
    
    
}



@end

猜你喜欢

转载自www.cnblogs.com/zhangqing979797/p/13401279.html