#import "ARTipsPageControl.h"
@interface ARTipsPageControl ()
{
UIImage *_currentPageImage;
UIImage *_pageImage;
}
@end
@implementation ARTipsPageControl
- (id)initWithFrame:(CGRect)frame withCurrentPageImage:(NSString *)currentPageImageName withPageImage:(NSString *)pageImageName{
self = [superinitWithFrame:frame];
if (self) {
//其他小点点图片
_currentPageImage = [UIImageimageNamed:currentPageImageName];
//当前小点点图片
_pageImage = [UIImageimageNamed:pageImageName];
}
returnself;
}
-(void)updateCircleImages
{
for (int i =0; i < [self.subviewscount]; i++) {
UIView* circleImageView = [self.subviewsobjectAtIndex:i];
CGSize size =_currentPageImage.size;
[circleImageView setFrame:CGRectMake(circleImageView.frame.origin.x, circleImageView.frame.origin.y, size.width, size.width)];
if (i ==self.currentPage){
circleImageView.backgroundColor = [UIColorcolorWithPatternImage:_currentPageImage];
}else{
circleImageView.backgroundColor = [UIColorcolorWithPatternImage:_pageImage];
}
//不会执行下列方法
if ([circleImageViewrespondsToSelector:@selector(setImage:)]) {
if (i ==self.currentPage){
((UIImageView *)circleImageView).image =_currentPageImage;
}else{
((UIImageView *)circleImageView).image =_pageImage;
}
}
}
}
//重写current方法
-(void)setCurrentPage:(NSInteger)page
{
[supersetCurrentPage:page];
[selfupdateCircleImages];
}
- (void)setNumberOfPages:(NSInteger)numberOfPages
{
[supersetNumberOfPages:numberOfPages];
[selfupdateCircleImages];
}
@end