Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ UIImage *gifImageNamed(NSString *imageName);
@property (nonatomic, assign) PageControlPosition pagePosition;


/**
* 描述文字的TextAlignment,默认为NSTextAlignmentCenter
*/
@property (nonatomic, assign) NSTextAlignment describeTextAlignment;


/**
* 如果pagePosition无法满足需求,可通过该属性设置分页控件的偏移量
* 在pagePosition的基础上进行偏移
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ + (void)initialize {
}
}

- (void)setDescribeTextAlignment:(NSTextAlignment)describeTextAlignment {
if (describeTextAlignment) {
self.describeLabel.textAlignment = describeTextAlignment;
}
}

#pragma mark 代码创建
- (instancetype)initWithFrame:(CGRect)frame {
Expand Down Expand Up @@ -181,7 +186,7 @@ - (void)setImageArray:(NSArray *)imageArray{
} else if ([imageArray[i] isKindOfClass:[NSString class]]){
//如果是网络图片,则先添加占位图片,下载完成后替换
if (_placeholderImage) [_images addObject:_placeholderImage];
else [_images addObject:[UIImage imageNamed:@"XRPlaceholder"]];
else [_images addObject:[UIImage imageNamed:@"XRPlaceholder" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil]];
[self downloadImages:i];
}
}
Expand Down Expand Up @@ -211,7 +216,7 @@ - (void)setDescribeArray:(NSArray *)describeArray{
_describeArray = describes;
}
self.describeLabel.hidden = NO;
_describeLabel.text = _describeArray[_currIndex];
self.describeLabel.text = _describeArray[_currIndex];
}
//重新计算pageControl的位置
self.pagePosition = _pagePosition;
Expand Down Expand Up @@ -260,36 +265,36 @@ - (void)setPageImage:(UIImage *)image andCurrentPageImage:(UIImage *)currentImag

#pragma mark 设置pageControl的指示器颜色
- (void)setPageColor:(UIColor *)color andCurrentPageColor:(UIColor *)currentColor {
_pageControl.pageIndicatorTintColor = color;
_pageControl.currentPageIndicatorTintColor = currentColor;
self.pageControl.pageIndicatorTintColor = color;
self.pageControl.currentPageIndicatorTintColor = currentColor;
}

#pragma mark 设置pageControl的位置
- (void)setPagePosition:(PageControlPosition)pagePosition {
_pagePosition = pagePosition;
_pageControl.hidden = (_pagePosition == PositionHide) || (_imageArray.count == 1);
if (_pageControl.hidden) return;
self.pageControl.hidden = (_pagePosition == PositionHide) || (_imageArray.count == 1);
if (self.pageControl.hidden) return;

CGSize size;
if (!_pageImageSize.width) {//没有设置图片,系统原有样式
size = [_pageControl sizeForNumberOfPages:_pageControl.numberOfPages];
size = [self.pageControl sizeForNumberOfPages:self.pageControl.numberOfPages];
size.height = 8;
} else {//设置图片了
size = CGSizeMake(_pageImageSize.width * (_pageControl.numberOfPages * 2 - 1), _pageImageSize.height);
size = CGSizeMake(_pageImageSize.width * (self.pageControl.numberOfPages * 2 - 1), _pageImageSize.height);
}
_pageControl.frame = CGRectMake(0, 0, size.width, size.height);
self.pageControl.frame = CGRectMake(0, 0, size.width, size.height);

CGFloat centerY = self.height - size.height * 0.5 - VERMARGIN - (_describeLabel.hidden?0: DES_LABEL_H);
CGFloat pointY = self.height - size.height - VERMARGIN - (_describeLabel.hidden?0: DES_LABEL_H);
CGFloat centerY = self.height - size.height * 0.5 - VERMARGIN - (self.describeLabel.hidden?0: DES_LABEL_H);
CGFloat pointY = self.height - size.height - VERMARGIN - (self.describeLabel.hidden?0: DES_LABEL_H);

if (_pagePosition == PositionDefault || _pagePosition == PositionBottomCenter)
_pageControl.center = CGPointMake(self.width * 0.5, centerY);
self.pageControl.center = CGPointMake(self.width * 0.5, centerY);
else if (_pagePosition == PositionTopCenter)
_pageControl.center = CGPointMake(self.width * 0.5, size.height * 0.5 + VERMARGIN);
self.pageControl.center = CGPointMake(self.width * 0.5, size.height * 0.5 + VERMARGIN);
else if (_pagePosition == PositionBottomLeft)
_pageControl.frame = CGRectMake(HORMARGIN, pointY, size.width, size.height);
self.pageControl.frame = CGRectMake(HORMARGIN, pointY, size.width, size.height);
else
_pageControl.frame = CGRectMake(self.width - HORMARGIN - size.width, pointY, size.width, size.height);
self.pageControl.frame = CGRectMake(self.width - HORMARGIN - size.width, pointY, size.width, size.height);

if (!CGPointEqualToPoint(_pageOffset, CGPointZero)) {
self.pageOffset = _pageOffset;
Expand All @@ -298,10 +303,10 @@ - (void)setPagePosition:(PageControlPosition)pagePosition {

- (void)setPageOffset:(CGPoint)pageOffset {
_pageOffset = pageOffset;
CGRect frame = _pageControl.frame;
CGRect frame = self.pageControl.frame;
frame.origin.x += pageOffset.x;
frame.origin.y += pageOffset.y;
_pageControl.frame = frame;
self.pageControl.frame = frame;
}


Expand Down Expand Up @@ -370,10 +375,10 @@ - (void)nextPage {
- (void)layoutSubviews {
[super layoutSubviews];
//有导航控制器时,会默认在scrollview上方添加64的内边距,这里强制设置为0
_scrollView.contentInset = UIEdgeInsetsZero;
self.scrollView.contentInset = UIEdgeInsetsZero;

_scrollView.frame = self.bounds;
_describeLabel.frame = CGRectMake(0, self.height - DES_LABEL_H, self.width, DES_LABEL_H);
self.scrollView.frame = self.bounds;
self.describeLabel.frame = CGRectMake(0, self.height - DES_LABEL_H, self.width, DES_LABEL_H);
//重新计算pageControl的位置
self.pagePosition = _pagePosition;
[self setScrollViewContentSize];
Expand Down Expand Up @@ -472,11 +477,11 @@ - (void)changeCurrentPageWithOffset:(CGFloat)offsetX {
if (offsetX < self.width * 1.5) {
NSInteger index = self.currIndex - 1;
if (index < 0) index = self.images.count - 1;
_pageControl.currentPage = index;
self.pageControl.currentPage = index;
} else if (offsetX > self.width * 2.5){
_pageControl.currentPage = (self.currIndex + 1) % self.images.count;
self.pageControl.currentPage = (self.currIndex + 1) % self.images.count;
} else {
_pageControl.currentPage = self.currIndex;
self.pageControl.currentPage = self.currIndex;
}
}

Expand Down Expand Up @@ -540,7 +545,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
//该方法用来修复滚动过快导致分页异常的bug
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (_changeMode == ChangeModeFade) return;
CGPoint currPointInSelf = [_scrollView convertPoint:_currImageView.frame.origin toView:self];
CGPoint currPointInSelf = [self.scrollView convertPoint:_currImageView.frame.origin toView:self];
if (currPointInSelf.x >= -self.width / 2 && currPointInSelf.x <= self.width / 2)
[self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
else [self changeToNext];
Expand Down