KJBannerView

  • Introduce yourself before writing infinite wheel broadcast picture library, infinite automatic cycle rolling, we have what needs can give me a message, continue to update…

The Demo address:KJBannerViewDemo

Function is introduced

√ 2, support four directions of scrolling, from left to right, from right to left, from top to bottom, from bottom to top √ 3, customize inheritance, customize different styles, For details, see Demo √ 4. Network dynamic graph and network picture and local picture rotation √ 5. Create and configure its properties in Storyboard and Xib √ 6


Method of use

Pod 'KJBannerView' #Copy the code

API & Property

NS_ASSUME_NONNULL_BEGIN IB_DESIGNABLE @interface KJBannerView : UIView /// delegate method @property (nonatomic,weak) id<KJBannerViewDelegate> delegate; @property (nonatomic,weak) id<KJBannerViewDataSource> dataSource; /// Block callback @property (nonatomic, readWrite,copy) void(^kSelectBlock)(KJBannerView *banner, NSInteger IDx); @property (nonatomic,readwrite,copy) void(^kScrollBlock)(KJBannerView *banner, NSInteger idx); /// pause the timer to scroll, note: implemented in viewDidDisappear - (void)kj_pauseTimer; /// continue timer scrolling, note: implemented in viewDidAppear - (void)kj_repauseTimer; - (void)kj_makeScrollToIndex:(NSInteger)index; /// Scroll to the specified location, Note: This is called after setting the data source. /// To use the navigation automatic layout, please call this method after setting the layout - (void)kj_useMasonry; / / * * * * * * * * * * * * * * * * * * * * * * * * data API * * * * * * * * * * * * * * * * * * * * * * * * / / / @ property data source (nonatomic, strong) NSArray<NSString*>*imageDatas; @property (nonatomic,assign) IBInspectable CGFloat autoTime; @property (nonatomic,assign) IBInspectable BOOL infiniteLoop; @property (nonatomic,assign) IBInspectable BOOL autoScroll; @property (nonatomic,assign) IBInspectable BOOL isZoom; @Property (nonatomic,assign) IBInspectable CGFloat itemWidth; @property (nonatomic,assign) IBInspectable CGFloat itemSpace; @property (nonatomic,assign) IBInspectable BOOL showPageControl; / / / rolling direction, the default @ property from right to left (nonatomic, assign) KJBannerViewRollDirectionType rollType; / / / @ property page controller (nonatomic, strong, readonly) KJPageView * pageControl; / / * * * * * * * * * * * * * * * * * * * * * * * * abandoned property methods * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / / / support custom Cell, The custom Cell must be inherited from kjBannerViewCell@property (nonatomic,strong) Class itemClass DEPRECATED_MSG_ATTRIBUTE("Please use dataSource [kj_BannerView:BannerViewCell:ImageDatas:Index:]"); @ the end / / * * * * * * * * * * * * * * * * * * * * take KJBannerViewCell attributes can be set up * * * * * * * * * * * * * * * * * * * * @ interface KJBannerView (KJBannerViewCell) / / / Clipping, default NO @ Property (nonatomic,assign) IBInspectable BOOL bannerScale; /// imagView rounded corner, default is 0px @property (nonatomic,assign) IBInspectable CGFloat bannerRadius; @property (nonatomic,strong) IBInspectable UIImage *placeholderImage; / / / by picture ContentMode, defaults to UIViewContentModeScaleToFill @ property (nonatomic, assign) UIViewContentMode bannerContentMode; / / / the style of the picture, the default KJBannerViewImageTypeNetIamge network images @ property (nonatomic, assign) KJBannerViewImageType imageType; NO @property (nonatomic,assign) BOOL openGIFCache; @end NS_ASSUME_NONNULL_ENDCopy the code

Introduce KJBannerView class

Class Functional areas
KJBannerView The master control unit of the wheel broadcast graph
KJPageView Custom paging controls
KJBannerViewFlowLayout Cell Zooming Management
KJBannerViewCell Base class. To customize, inherit the Cell
KJBannerDatasInfo Built-in BannerViewCell data model
KJLoadImageView Does not rely on the third party network to load the picture display control
KJBannerTool Utility methods
KJBannerViewType Enumeration folder
KJBannerViewProtocol Entrustment agreement
NSTimer+KJSolve Timer classification
UIImage+KJBannerGIF Dynamic graph classification
KJBannerViewCacheManager Cache tool
KJBannerViewDownloader Network request tool
KJBannerViewLoadManager Network map download tool

Support Xib quick setting properties

rendering

Download the test effect drawing, which is obtained by semaphore method

Usage examples

Automatic navigation layout

To use automatic layout for navigation, call the method kj_useMasonry after setting the layout

- (void)setMasonry{ self.banner2 = [[KJBannerView alloc]init]; self.banner2.autoTime = 2; self.banner2.isZoom = YES; self.banner2.itemSpace = -10; self.banner2.itemWidth = 280; self.banner2.delegate = self; self.banner2.dataSource = self; self.banner2.imageType = KJBannerViewImageTypeMix; self.banner2.pageControl.pageType = PageControlStyleSizeDot; self.banner2.pageControl.displayType = KJPageControlDisplayTypeRight; Self. Banner2. PageControl. BackgroundColor = [UIColor. BlackColor colorWithAlphaComponent: 0.5]; [self.backView addSubview:self.banner2]; [self.banner2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.mas_equalTo(0); }]; [self.banner2 kj_useMasonry]; self.banner2.imageDatas = self.temp; }Copy the code

Xib layout

- (void)setXib{ self.banner.delegate = self; self.banner.pageControl.pageType = PageControlStyleRectangle; self.banner.pageControl.selectColor = UIColor.greenColor; self.banner.pageControl.dotwidth = 20; self.banner.pageControl.dotheight = 2; The self. The banner. PageControl. BackgroundColor = [UIColor. BlackColor colorWithAlphaComponent: 0.5]; self.banner.pageControl.displayType = KJPageControlDisplayTypeLeft; self.banner.imageType = KJBannerViewImageTypeMix; self.banner.bannerScale = YES; self.banner.rollType = KJBannerViewRollDirectionTypeBottomToTop; self.banner.bannerContentMode = UIViewContentModeScaleAspectFill; self.banner.imageDatas = @[tu2,gif2,@"IMG_0139",@"tu3"]; [self.banner kj_makeScrollToIndex:1]; }Copy the code

Delegate custom controls

#pragma mark - KJBannerViewDataSource - (UIView*)kj_BannerView:(KJBannerView*)banner BannerViewCell:(KJBannerViewCell*)bannercell ImageDatas:(NSArray*)imageDatas Index:(NSInteger)index{ KJBannerModel *model = imageDatas[index]; CGRect rect = {0, 0, 100, 20}; UILabel *label = [[UILabel alloc]initWithFrame:rect]; If (index == 0) {label.text = @" customize different controls "; label.frame = CGRectMake(0, 0, bannercell.contentView.frame.size.width, 40); label.font = [UIFont boldSystemFontOfSize:35]; label.textColor = UIColor.greenColor; label.textAlignment = NSTextAlignmentCenter; } KJLoadImageView *imageView = [[KJLoadImageView alloc]initWithFrame:bannercell.contentView.bounds]; imageView.kj_isScale = YES; [imageView kj_setImageWithURLString:model.customImageUrl Placeholder:[UIImage imageNamed:@"tu3"]]; [imageView addSubview:label]; return imageView; }Copy the code

Inheritance custom control

- (void)setText{ self.banner3.showPageControl = NO; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" self.banner3.itemClass = [KJCollectionViewCell class]; #pragma clang diagnostic pop self.banner3.rollType = KJBannerViewRollDirectionTypeBottomToTop; Self.banner3. imageDatas = @[@" test text scroll ",@" feel good, please give me a star ",@" if you have any questions, please contact me ",@" email: [email protected]"]; }Copy the code

Customize Cell usage

- (void)setModel:(NSObject*)model{
    self.label.text = (NSString*)model;
}
Copy the code

This is the end of the round broadcast diagram introduction, there are related to supplement, writing an article is not easy, but also please point a **Little stars* * portal