码迷,mamicode.com
首页 > 其他好文 > 详细

轮播图

时间:2017-11-02 13:06:15      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:copy   jin   class   url   dsc   out   loop   文字   sar   

@property (nonatomic,strong) NSArray *imagesURLStrings;

@property (weak, nonatomic) IBOutlet UIScrollView *demoContainerView;

图片配文字数组

NSArray *titles = @[@"a ",

                    @"b",

                    @"c",

                    @"d"

                    ];

1.加载本地图片 --- 创建不带标题的图片轮播器

NSArray *imageNames = @[@"jinhui1",

                        @"jinhui3",

                        @"jinhui4",

                        @"jinhui5",

                        @"jinhui6" // 本地图片请填写全名

                        ];

 

     SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0,         _demoContainerView.frame.size.width, _demoContainerView.frame.size.height) shouldInfiniteLoop:YES imageNamesGroup:imageNames];

cycleScrollView.delegate = self;

cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolAlimentRight;

[_demoContainerView addSubview:cycleScrollView];

cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;

//         --- 轮播时间间隔,默认1.0秒,可自定义

cycleScrollView.autoScrollTimeInterval = 4.0;

 

2.网络图片加载 --- 创建带标题的图片轮播器

  NSString *string=@"http://";

        NSString *string1=@"/picture/jinhui1.png";

        NSString *string2=@":";

        NSString *urlString =[string stringByAppendingFormat:@"%@%@%@%@",_ip,string2,_duankouhao,string1];

        NSString *string22=@"http://";

        NSString *string12=@"/picture/jinhui2.png";

        NSString *string222=@":";

        NSString *urlString2 =[string22 stringByAppendingFormat:@"%@%@%@%@",_ip,string222,_duankouhao,string12];

        NSString *string33=@"http://";

        NSString *string13=@"/picture/jinhui3.png";

        NSString *string23=@":";

        NSString *urlString3 =[string33 stringByAppendingFormat:@"%@%@%@%@",_ip,string23,_duankouhao,string13];

        NSString *string44=@"http://";

        NSString *string14=@"/picture/jinhui4.png";

        NSString *string24=@":";

        NSString *urlString4 =[string44 stringByAppendingFormat:@"%@%@%@%@",_ip,string24,_duankouhao,string14];

        NSString *string55=@"http://";

        NSString *string15=@"/picture/jinhui5.png";

        NSString *string25=@":";

        NSString *urlString5 =[string55 stringByAppendingFormat:@"%@%@%@%@",_ip,string25,_duankouhao,string15];

        

        NSArray *imagesURLStrings = @[

                                      urlString,urlString2,urlString3,urlString4,urlString5

                                      ];

        _imagesURLStrings=imagesURLStrings;

 

 

2.1网络图片加载 --- 创建带标题的图片轮播器

SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 280, self.view.frame.size.width, _demoContainerView.frame.size.height) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];

cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;

//cycleScrollView2.titlesGroup = titles;

cycleScrollView2.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色

[_demoContainerView addSubview:cycleScrollView2];

//         --- 模拟加载延迟

//dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

//    cycleScrollView2.imageURLStringsGroup = imagesURLStrings;

//});

//

/*

 block监听点击方式

 

 cycleScrollView2.clickItemOperationBlock = ^(NSInteger index) {

 NSLog(@">>>>>  %ld", (long)index);

 };

 

 */

 

2.2网络加载 --- 创建自定义图片的pageControlDot的图片轮播器

SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.view.frame.size.width, _demoContainerView.frame.size.height) delegate:self placeholderImage:nil];

 

cycleScrollView3.imageURLStringsGroup = _imagesURLStrings;

 

[_demoContainerView addSubview:cycleScrollView3];

 

 

2.3网络加载 --- 创建只横向滚动展示文字的轮播器

// 由于模拟器的渲染问题,如果发现轮播时有一条线不必处理,模拟器放大到100%或者真机调试是不会出现那条线的

SDCycleScrollView *cycleScrollView4 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 750, w, 40) delegate:self placeholderImage:nil];

cycleScrollView4.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    

cycleScrollView4.onlyDisplayText = YES;

 

NSMutableArray *titlesArray = [NSMutableArray new];

[titlesArray addObject:@"纯文字上下滚动轮播"];

[titlesArray addObject:@"纯文字上下滚动轮播 "];

//[titlesArray addObjectsFromArray:titles];

cycleScrollView4.titlesGroup = [titlesArray copy];

 

[_demoContainerView addSubview:cycleScrollView4];

 

 

 

#pragma mark - SDCycleScrollViewDelegate

 

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index

{

    NSLog(@"---点击了第%ld张图片", (long)index);

   

    // [self.navigationController pushViewController:[NSClassFromString(@"DemoVCWithXib") new] animated:YES];

}

 

 

 

// 滚动到第几张图回调

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index

{

    // NSLog(@">>>>>> 滚动到第%ld张图", (long)index);

}

 

轮播图

标签:copy   jin   class   url   dsc   out   loop   文字   sar   

原文地址:http://www.cnblogs.com/wangqitze/p/7771468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!