diff --git a/LCBannerView.podspec b/LCBannerView.podspec index 7bdd7f1..6f949ff 100644 --- a/LCBannerView.podspec +++ b/LCBannerView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "LCBannerView" - s.version = "1.2.3" + s.version = "1.2.5" s.summary = "A very popular and highly customized banner view! Infinite loop! Support: http://LeoDev.me" s.homepage = "https://github.com/iTofu/LCBannerView" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/LCBannerView/LCBannerView.h b/LCBannerView/LCBannerView.h index e97fb2a..2392c50 100644 --- a/LCBannerView/LCBannerView.h +++ b/LCBannerView/LCBannerView.h @@ -1,13 +1,12 @@ // // LCBannerView.h -// LCBannerViewDemo // // Created by Leo on 15/11/30. // Copyright © 2015年 Leo. All rights reserved. // // GitHub: http://github.com/iTofu // Mail: mailto:devtip@163.com -// V 1.2.3 +// V 1.2.5 #import @@ -19,6 +18,12 @@ @optional +/** + * LCBannerView delegate method. + * + * @param bannerView LCBannerView + * @param index clicked index + */ - (void)bannerView:(LCBannerView *)bannerView didClickedImageIndex:(NSInteger)index; @end @@ -28,10 +33,10 @@ @interface LCBannerView : UIView -#pragma mark - Property +#pragma mark - Properties /** - * Page control view bottom distance. Default is `10.0f`. + * Page control to bottom distance. Default is `10.0f`. */ @property (nonatomic, assign) CGFloat pageDistance; @@ -44,7 +49,7 @@ #pragma mark - Class methods /** - * init a LCBannerView object from local + * Init a LCBannerView object from local. * * @param frame frame * @param delegate delegate @@ -65,7 +70,7 @@ currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor pageIndicatorTintColor:(UIColor *)pageIndicatorTintColor; /** - * init a LCBannerView object from internet + * Init a LCBannerView object from internet. * * @param frame frame * @param delegate delegate @@ -89,7 +94,7 @@ currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor #pragma mark - Instance methods /** - * init a LCBannerView object from local + * Init a LCBannerView object from local. * * @param frame frame * @param delegate delegate @@ -110,7 +115,7 @@ currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor pageIndicatorTintColor:(UIColor *)pageIndicatorTintColor; /** - * init a LCBannerView object from internet + * Init a LCBannerView object from internet. * * @param frame frame * @param delegate delegate diff --git a/LCBannerView/LCBannerView.m b/LCBannerView/LCBannerView.m index 429231d..7984e24 100644 --- a/LCBannerView/LCBannerView.m +++ b/LCBannerView/LCBannerView.m @@ -1,6 +1,5 @@ // // LCBannerView.m -// LCBannerViewDemo // // Created by Leo on 15/11/30. // Copyright © 2015年 Leo. All rights reserved. @@ -33,7 +32,7 @@ @interface LCBannerView () @implementation LCBannerView + (instancetype)bannerViewWithFrame:(CGRect)frame delegate:(id)delegate imageName:(NSString *)imageName count:(NSInteger)count timerInterval:(NSInteger)timeInterval currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor pageIndicatorTintColor:(UIColor *)pageIndicatorTintColor { - + return [[self alloc] initWithFrame:frame delegate:delegate imageName:imageName @@ -44,7 +43,7 @@ + (instancetype)bannerViewWithFrame:(CGRect)frame delegate:(id)delegate imageURLs:(NSArray *)imageURLs placeholderImage:(NSString *)placeholderImage timerInterval:(NSInteger)timeInterval currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor pageIndicatorTintColor:(UIColor *)pageIndicatorTintColor { - + return [[self alloc] initWithFrame:frame delegate:delegate imageURLs:imageURLs @@ -55,25 +54,25 @@ + (instancetype)bannerViewWithFrame:(CGRect)frame delegate:(id)delegate imageName:(NSString *)imageName count:(NSInteger)count timerInterval:(NSInteger)timeInterval currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor pageIndicatorTintColor:(UIColor *)pageIndicatorTintColor { - + if (self = [super initWithFrame:frame]) { - + self.delegate = delegate; self.imageName = imageName; self.count = count; self.timerInterval = timeInterval; self.currentPageIndicatorTintColor = currentPageIndicatorTintColor; self.pageIndicatorTintColor = pageIndicatorTintColor; - + [self setupMainView]; } return self; } - (instancetype)initWithFrame:(CGRect)frame delegate:(id)delegate imageURLs:(NSArray *)imageURLs placeholderImage:(NSString *)placeholderImage timerInterval:(NSInteger)timeInterval currentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor pageIndicatorTintColor:(UIColor *)pageIndicatorTintColor { - + if (self = [super initWithFrame:frame]) { - + self.delegate = delegate; self.imageURLs = imageURLs; self.count = imageURLs.count; @@ -81,111 +80,111 @@ - (instancetype)initWithFrame:(CGRect)frame delegate:(id)d self.currentPageIndicatorTintColor = currentPageIndicatorTintColor; self.pageIndicatorTintColor = pageIndicatorTintColor; self.placeholderImage = placeholderImage; - + [self setupMainView]; } return self; } - (void)setupMainView { - + CGFloat scrollW = self.frame.size.width; CGFloat scrollH = self.frame.size.height; - + // set up scrollView [self addSubview:({ - + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, scrollW, scrollH)]; - + for (int i = 0; i < self.count + 2; i++) { - + NSInteger tag = 0; NSString *currentImageName = nil; - + if (i == 0) { - + tag = self.count; - + currentImageName = [NSString stringWithFormat:@"%@_%02ld", self.imageName, (long)self.count]; - + } else if (i == self.count + 1) { - + tag = 1; - + currentImageName = [NSString stringWithFormat:@"%@_01", self.imageName]; - + } else { - + tag = i; - + currentImageName = [NSString stringWithFormat:@"%@_%02d", self.imageName, i]; } - + UIImageView *imageView = [[UIImageView alloc] init]; imageView.tag = tag; - + if (self.imageName.length > 0) { // from local - + UIImage *image = [UIImage imageNamed:currentImageName]; if (!image) { - + NSLog(@"ERROR: No image named `%@`!", currentImageName); } - + imageView.image = image; - + } else { // from internet - + [imageView sd_setImageWithURL:[NSURL URLWithString:self.imageURLs[tag - 1]] placeholderImage:self.placeholderImage.length > 0 ? [UIImage imageNamed:self.placeholderImage] : nil]; } - + imageView.clipsToBounds = YES; imageView.userInteractionEnabled = YES; imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.frame = CGRectMake(scrollW * i, 0, scrollW, scrollH); [scrollView addSubview:imageView]; - + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTaped:)]; [imageView addGestureRecognizer:tap]; } - + scrollView.delegate = self; scrollView.scrollsToTop = NO; scrollView.pagingEnabled = YES; scrollView.showsHorizontalScrollIndicator = NO; scrollView.contentOffset = CGPointMake(scrollW, 0); scrollView.contentSize = CGSizeMake((self.count + 2) * scrollW, 0); - + self.scrollView = scrollView; })]; - + [self addTimer]; - + // set up pageControl [self addSubview:({ - + UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, scrollH - 10.0f - LCPageDistance, scrollW, 10.0f)]; pageControl.numberOfPages = self.count; pageControl.userInteractionEnabled = NO; pageControl.currentPageIndicatorTintColor = self.currentPageIndicatorTintColor ?: [UIColor orangeColor]; pageControl.pageIndicatorTintColor = self.pageIndicatorTintColor ?: [UIColor lightGrayColor]; - + self.pageControl = pageControl; })]; } - (void)imageViewTaped:(UITapGestureRecognizer *)tap { - + if ([self.delegate respondsToSelector:@selector(bannerView:didClickedImageIndex:)]) { - + [self.delegate bannerView:self didClickedImageIndex:tap.view.tag - 1]; } } - (void)setPageDistance:(CGFloat)pageDistance { _pageDistance = pageDistance; - + if (pageDistance != LCPageDistance) { CGRect frame = self.pageControl.frame; frame.origin.y = self.frame.size.height - 10.0f - pageDistance; @@ -195,11 +194,11 @@ - (void)setPageDistance:(CGFloat)pageDistance { - (void)setNotScrolling:(BOOL)notScrolling { _notScrolling = notScrolling; - + if (notScrolling) { self.pageControl.hidden = YES; self.scrollView.scrollEnabled = NO; - + if (self.timer) { [self removeTimer]; } @@ -209,26 +208,26 @@ - (void)setNotScrolling:(BOOL)notScrolling { #pragma mark - Timer - (void)addTimer { - + self.timer = [NSTimer scheduledTimerWithTimeInterval:self.timerInterval target:self selector:@selector(nextImage) userInfo:nil repeats:YES]; - + [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; } - (void)removeTimer { - + if (self.timer) { - + [self.timer invalidate]; - + self.timer = nil; } } - (void)nextImage { - + NSInteger currentPage = self.pageControl.currentPage; - + [self.scrollView setContentOffset:CGPointMake((currentPage + 2) * self.scrollView.frame.size.width, 0) animated:YES]; } @@ -236,59 +235,59 @@ - (void)nextImage { #pragma mark - UIScrollView Delegate Methods - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - + CGFloat scrollW = self.scrollView.frame.size.width; NSInteger currentPage = self.scrollView.contentOffset.x / scrollW; - + if (currentPage == self.count + 1) { - + self.pageControl.currentPage = 0; - + } else if (currentPage == 0) { - + self.pageControl.currentPage = self.count; - + } else { - + self.pageControl.currentPage = currentPage - 1; } } - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { - + [self scrollViewDidEndDecelerating:scrollView]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { - + CGFloat scrollW = self.scrollView.frame.size.width; NSInteger currentPage = self.scrollView.contentOffset.x / scrollW; - + if (currentPage == self.count + 1) { - + self.pageControl.currentPage = 0; - + [self.scrollView setContentOffset:CGPointMake(scrollW, 0) animated:NO]; - + } else if (currentPage == 0) { - + self.pageControl.currentPage = self.count; - + [self.scrollView setContentOffset:CGPointMake(self.count * scrollW, 0) animated:NO]; - + } else { - + self.pageControl.currentPage = currentPage - 1; } } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { - + [self removeTimer]; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { - + [self addTimer]; } diff --git a/README.md b/README.md index f4243b0..d75fcaf 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ In me the tiger sniffs the rose. 心有猛虎,细嗅蔷薇。 ```` -Welcome to visit my blog: ✨ +Welcome to my blog: ✨ [**中文介绍**](https://github.com/iTofu/LCBannerView/blob/master/README-zh_CN.md) @@ -28,7 +28,7 @@ This is a display of advertising or information. You can using the images from **Local** or **Internet**. -And it won't affect other scrollViews' `scrollsToTop` propertie. +And it won't affect other scrollViews' `scrollsToTop` properties. If you feel good, please give me a star, thank you very much! ⭐️ @@ -124,6 +124,11 @@ Just drag the LCBannerView folder into your project. ## Release +### V 1.2.5 + +* Update README and some documents. + + ### V 1.2.2 * Update CocoaPods source URL.