iOS實現圖片無限輪播之使用第三方庫SDCycleScrollView(轉)


下載鏈接:github不斷更新地址:https://github.com/gsdios/SDCycleScrollView

 

#import "ViewController.h"

#import "SDCycleScrollView.h"

@interface ViewController () <</span>SDCycleScrollViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed:0.98green:0.98 blue:0.98 alpha:0.99];

UIImageView *backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"005.jpg"]];

frame = self.view.bounds;

self.view addSubview:backgroundView];

    

    // 情景一:采用本地圖片實現

NSArray *images = @[[UIImage imageNamed:@"h1.jpg"],

UIImage imageNamed:@"h2.jpg"],

UIImage imageNamed:@"h3.jpg"],

UIImage imageNamed:@"h4.jpg"]

];

    

    // 情景二:采用網絡圖片實現

NSArray *imagesURLStrings = @[

                           @"https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf=425,260,50/sign=a4b3d7085dee3d6d2293d48b252b5910/0e2442a7d933c89524cd5cd4d51373f0830200ea.jpg",

                           @"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf=425,260,50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg",

                          @"http://c.hiphotos.baidu.com/image/w=400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"

];

    

    // 情景三:圖片配文字

NSArray *titles = @[@"感謝您的支持,如果下載的",

@"如果代碼在使用過程中出現問題",

@"您可以發郵件到gsdios@126.com",

@"感謝您的支持"

];

    

    

    

    

    CGFloat w = self.view.bounds.size.width;

    

    // 本地加載 --- 創建不帶標題的圖片輪播器

SDCycleScrollView *cycleScrollView = [SDCycleScrollViewcycleScrollViewWithFrame:CGRectMake(0, 100, w, 180)imagesGroup:images];

    cycleScrollView.infiniteLoop = YES;

delegate = self;

    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;

self.view addSubview:cycleScrollView];

    //         --- 輪播時間間隔,默認1.0秒,可自定義

    //cycleScrollView.autoScrollTimeInterval = 4.0;

    

    

     //網絡加載 --- 創建帶標題的圖片輪播器

    SDCycleScrollView *cycleScrollView2 = [SDCycleScrollViewcycleScrollViewWithFrame:CGRectMake(0320, w, 180)imageURLStringsGroup:nil]; // 模擬網絡延時情景

    cycleScrollView2.pageControlAliment =SDCycleScrollViewPageContolAlimentRight;

delegate = self;

titlesGroup = titles;

dotColor = [UIColor yellowColor]; // 自定義分頁控件小圓標顏色

placeholderImage = [UIImageimageNamed:@"placeholder"];

self.view addSubview:cycleScrollView2];

    

模擬加載延遲

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

imageURLStringsGroup = imagesURLStrings;

    });

    

    // 清除緩存

//    [cycleScrollView2 clearCache];

    

}



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

    NSLog(@"---點擊了第%ld張圖片", index);


 

@end


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM