性能无优化的图片轮播

//
// ViewController.m
// 图片轮播
//
// Created by apple on 16/4/20.
// Copyright © 2016年 cuijw. All rights reserved.
//

import “ViewController.h”

define SEECRE_SIZE self.view.bounds.size

@interface ViewController ()
@property (nonatomic,strong)UIScrollView * scrollView;
@property (nonatomic,strong)UIPageControl * pageControl;
@property (nonatomic,copy)NSArray * arr;
@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
    _arr= @[@”1.jpg”,@”2.jpg”,@”3.jpg”,@”4.jpg”,@”5.jpg”,@”6.jpg”,@”7.jpg”,@”8.jpg”];
    // _arr= @[@”1.jpg”,@”2.jpg”,@”3.jpg”];
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 25, SEECRE_SIZE.width, SEECRE_SIZE.width*1.5)];
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.contentSize = CGSizeMake(SEECRE_SIZE.width*(_arr.count+2), 0);
    for (int i = 0; i<_arr.count+2; i++) {
    UIImageView * iamge = [[UIImageView alloc]init];
    if (i==0) {

        iamge.image = [UIImage imageNamed:_arr[_arr.count-1]];
    }
    else if (i == _arr.count+1)
    {
        iamge.image = [UIImage imageNamed:_arr[0]];
    }
    else
    {
        iamge.image = [UIImage imageNamed:_arr[i-1]];
    }
    
    
    iamge.frame = CGRectMake(SEECRE_SIZE.width*i, 0, SEECRE_SIZE.width, SEECRE_SIZE.width*1.5);
    [self.scrollView addSubview:iamge];
    

    }
    self.pageControl = [[UIPageControl alloc]init];
    self.pageControl.frame = CGRectMake(100, SEECRE_SIZE.height-80, 200, 44);
    [self.view addSubview:self.pageControl];
    self.pageControl.numberOfPages = _arr.count;
    self.pageControl.currentPage = 0;
    self.pageControl.pageIndicatorTintColor = [UIColor magentaColor];
    self.pageControl.currentPageIndicatorTintColor = [UIColor blueColor];

}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger currpage = scrollView.contentOffset.x/SEECRE_SIZE.width;
if (currpage==0) {
currpage = _arr.count-1;
self.scrollView.contentOffset = CGPointMake(SEECRE_SIZE.width*_arr.count, 0);
}
else if (currpage == _arr.count+1)
{
self.scrollView.contentOffset = CGPointMake(SEECRE_SIZE.width, 0);
currpage =0;
}
else
{
currpage = currpage-1;
}
self.pageControl.currentPage = currpage;
}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值