iOS輪播循環滾動:WHCycleScrollView
WHCycleScrollView
- 輪播循環滾動,可自定義循環時間,方向;
- 數據源支持URL和本地資源圖片同時混用;
- 通過block和協議回調點擊和長按事件;
- 集成UIPageControl,且支持左中右三個位置; </ul>
一行代碼實現自動輪播和pageControl
WHCycleScrollView* cycleScrollView = [WHCycleScrollView cycleScrollViewWithFrame:self.view.bounds dataSource:urls pageControl:YES autoCycle:YES];
屬性說明:
@property (nonnull, nonatomic, strong) NSArray * dataSource;
dataSource支持URL和本地圖片名混用,URL元素以NSURL形式,本地圖片以NSString形式放入數組中。在數據源有變化時,直接設置此屬性即可,PageControl會跟著變化。
@property (nullable, nonatomic, strong) UIImage * placeholderImage;
placeholderImage是加載URL資源時的占位圖
@property (nonatomic, assign) BOOL needPageControl; //default is NO
needPageControl默認為NO,如果需要可設置為YES,即可集成
@property (nonatomic, assign) WHPageControlLocation pageControlType;
pageControlType是設置pageControl位置的屬性,有三個枚舉值,默認是在中間 typedef NS_ENUM(NSInteger, WHPageControlLocation ){ WHPageControlLocationLeft, WHPageControlLocationCenter, WHPageControlLocationRight, };
@property (nullable, nonatomic, strong) UIColor * pageIndicatorTintColor; @property (nullable, nonatomic, strong) UIColor *currentPageIndicatorTintColor;
這兩個屬性用于設置pageContol的當前page顏色和其它page顏色
@property (nonatomic, assign) BOOL needAutoCycle;
needAutoCycle默認為NO,如果需要輪播則設置為YES
@property (nonatomic, assign) NSTimeInterval autoCycleInterval;
autoCycleInterval用于設置輪播間隔,默認為5.0f
@property (nonatomic, assign) WHCycleDirection cycleDirection
cycleDirection用于設置輪播滾動方向,默認是向右 typedef NS_ENUM(NSInteger, WHCycleDirection){ WHCycleDirectionRight, WHCycleDirectionLeft, };
@property (nullable, nonatomic, copy) void (^tapAction)(NSInteger index);
tapAction,單擊事件block回調
@property (nullable, nonatomic, copy) void (^longPressAction)(NSInteger index);
longPressAction,長按事件block回調
- 除了用block回調外,還可以通過WHCycleScrollViewDelegate協議來回調
- ps:URL加載采用SDWebImage