1. 程式人生 > 其它 >OC Control SDCycleScrollView(圖片輪播器)

OC Control SDCycleScrollView(圖片輪播器)

技術標籤:UI的封裝iosobjective-cswiftxcode

一直覺得自己寫的不是技術,而是情懷,一個個的教程是自己這一路走來的痕跡。靠專業技能的成功是最具可複製性的,希望我的這條路能讓你們少走彎路,希望我能幫你們抹去知識的蒙塵,希望我能幫你們理清知識的脈絡,希望未來技術之巔上有你們也有我。

說明:這個控制元件是別人寫的
在這裡插入圖片描述

控制元件提供的方法

/** 初始輪播圖(推薦使用) */
+ (instancetype)cycleScrollViewWithFrame:(CGRect)frame delegate:(id<SDCycleScrollViewDelegate>)delegate placeholderImage:
(UIImage *)placeholderImage; + (instancetype)cycleScrollViewWithFrame:(CGRect)frame imageURLStringsGroup:(NSArray *)imageURLStringsGroup; /** 本地圖片輪播初始化方式 */ + (instancetype)cycleScrollViewWithFrame:(CGRect)frame imageNamesGroup:(NSArray *)imageNamesGroup; /** 本地圖片輪播初始化方式2,infiniteLoop:是否無限迴圈 */ + (instancetype)
cycleScrollViewWithFrame:(CGRect)frame shouldInfiniteLoop:(BOOL)infiniteLoop imageNamesGroup:(NSArray *)imageNamesGroup; // 資料來源介面 // /** 網路圖片 url string 陣列 */ @property (nonatomic, strong) NSArray *imageURLStringsGroup; /** 每張圖片對應要顯示的文字陣列 */ @property (nonatomic, strong) NSArray *titlesGroup; /** 本地圖片陣列 */
@property (nonatomic, strong) NSArray *localizationImageNamesGroup; // 滾動控制介面 // /** 自動滾動間隔時間,預設2s */ @property (nonatomic, assign) CGFloat autoScrollTimeInterval; /** 是否無限迴圈,預設Yes */ @property (nonatomic,assign) BOOL infiniteLoop; /** 是否自動滾動,預設Yes */ @property (nonatomic,assign) BOOL autoScroll; /** 圖片滾動方向,預設為水平滾動 */ @property (nonatomic, assign) UICollectionViewScrollDirection scrollDirection; @property (nonatomic, weak) id<SDCycleScrollViewDelegate> delegate; /** block方式監聽點選 */ @property (nonatomic, copy) void (^clickItemOperationBlock)(NSInteger currentIndex); /** block方式監聽滾動 */ @property (nonatomic, copy) void (^itemDidScrollOperationBlock)(NSInteger currentIndex); /** 解決viewWillAppear時出現時輪播圖卡在一半的問題,在控制器viewWillAppear時呼叫此方法 */ - (void)adjustWhenControllerViewWillAppera; // 自定義樣式介面 // /** 輪播圖片的ContentMode,預設為 UIViewContentModeScaleToFill */ @property (nonatomic, assign) UIViewContentMode bannerImageViewContentMode; /** 佔位圖,用於網路未載入到圖片時 */ @property (nonatomic, strong) UIImage *placeholderImage; /** 是否顯示分頁控制元件 */ @property (nonatomic, assign) BOOL showPageControl; /** 是否在只有一張圖時隱藏pagecontrol,預設為YES */ @property(nonatomic) BOOL hidesForSinglePage; /** 只展示文字輪播 */ @property (nonatomic, assign) BOOL onlyDisplayText; /** pagecontrol 樣式,預設為動畫樣式 */ @property (nonatomic, assign) SDCycleScrollViewPageContolStyle pageControlStyle; /** 分頁控制元件位置 */ @property (nonatomic, assign) SDCycleScrollViewPageContolAliment pageControlAliment; /** 分頁控制元件距離輪播圖的底部間距(在預設間距基礎上)的偏移量 */ @property (nonatomic, assign) CGFloat pageControlBottomOffset; /** 分頁控制元件距離輪播圖的右邊間距(在預設間距基礎上)的偏移量 */ @property (nonatomic, assign) CGFloat pageControlRightOffset; /** 分頁控制元件小圓標大小 */ @property (nonatomic, assign) CGSize pageControlDotSize; /** 當前分頁控制元件小圓標顏色 */ @property (nonatomic, strong) UIColor *currentPageDotColor; /** 其他分頁控制元件小圓標顏色 */ @property (nonatomic, strong) UIColor *pageDotColor; /** 當前分頁控制元件小圓標圖片 */ @property (nonatomic, strong) UIImage *currentPageDotImage; /** 其他分頁控制元件小圓標圖片 */ @property (nonatomic, strong) UIImage *pageDotImage; /** 輪播文字label字型顏色 */ @property (nonatomic, strong) UIColor *titleLabelTextColor; /** 輪播文字label字型大小 */ @property (nonatomic, strong) UIFont *titleLabelTextFont; /** 輪播文字label背景顏色 */ @property (nonatomic, strong) UIColor *titleLabelBackgroundColor; /** 輪播文字label高度 */ @property (nonatomic, assign) CGFloat titleLabelHeight; /** 輪播文字label對齊方式 */ @property (nonatomic, assign) NSTextAlignment titleLabelTextAlignment; // 清除快取介面 // /** 清除圖片快取(此次升級後統一使用SDWebImage管理圖片載入和快取) */ + (void)clearImagesCache; /** 清除圖片快取(相容舊版本方法) */ - (void)clearCache;

使用

<SDCycleScrollViewDelegate>

@property (nonatomic,strong) SDCycleScrollView *cycleScrollView;

self.cycleScrollView.imageURLStringsGroup = slideList;

    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"spellgroup_nopic_normalNopic"]];
    [self addSubview:self.cycleScrollView];
    self.cycleScrollView.userInteractionEnabled = YES;
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    self.cycleScrollView.currentPageDotColor = [UIColor whiteColor];
    self.cycleScrollView.autoScrollTimeInterval = 3.0;
    self.cycleScrollView.autoScroll = YES;
    self.cycleScrollView.borderRadius(5).makeCons(^{
      make.top.equal.view(self.line).bottom.constants(10);
      make.bottom.equal.view(self.contentView).constants(-10);
      make.left.equal.view(self.contentView).constants(10);
      make.right.equal.view(self.contentView).constants(-10);
    });

#pragma  mark Delegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{

}

效果

在這裡插入圖片描述