滚动视图

{
    int k;
}
@property(nonatomic,strong)UIScrollView*src;
@property(nonatomic,strong)UIPageControl*pag;
@property(nonatomic,strong)NSTimer*time;



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor=[UIColor whiteColor];
    self.view.backgroundColor=[UIColor whiteColor];
    //初始化ScrollView,设定位置
    self.src = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 360)];
//    self.src.backgroundColor = [UIColor greenColor];
    //设置显示内容的大小,这里表示可以下滑十倍原高度
    self.src.contentSize = CGSizeMake(3*self.view.frame.size.width, 0);
    //设置当滚动到边缘继续滚时是否像橡皮经一样弹回
    self.src.bounces = YES;
    //设置滚动条指示器的类型,默认是白边界上的黑色滚动条
    self.src.pagingEnabled = YES;
    //        self.src.indicatorStyle = UIScrollViewIndicatorStyleDefault;
    
    self.src.bouncesZoom = YES;
    //设置委托
    self.src.delegate = self;
    NSArray*arr=@[@"WechatIMG2.jpeg",@"WechatIMG3.jpeg",@"WechatIMG4.jpeg"];
    for (int i=0; i<3; i++) {
        
        //创建对象
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(i*self.view.frame.size.width, 0, self.view.frame.size.width, 360)];
        //添加图片
        img.image = [UIImage imageNamed:arr[i]];
        //添加到滚动视图
        [self.src addSubview:img];
        
    }
    [self.view addSubview:self.src];
    self.pag=[[UIPageControl alloc] initWithFrame:CGRectMake(120, 300, 150, 25)];
    self.pag.currentPage=0;
    self.pag.numberOfPages=3;
//    选中颜色
    self.pag.currentPageIndicatorTintColor=[UIColor orangeColor];
    self.pag.pageIndicatorTintColor=[UIColor whiteColor];
    [self.view addSubview:self.pag];
    //设置定时器
    self.time = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(ding) userInfo:nil repeats:YES];
    //开启
    [self.time fire];
    

    
   
    
   
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //设置偏移量
    self.pag.currentPage = self.src.contentOffset.x/self.view.frame.size.width;
}
- (void)ding{
    [self.src setContentOffset:CGPointMake(k*self.view.frame.size.width, 0)];
    k++;
    if (k>2) {
        k=0;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值