ios UIPageControl 點顏色設(shè)置的總結(jié)

1、寫一個繼承UIPageControl類

2、重寫UIPageControl的 setCurrentPage方法

3、修改當前點的顏色

code:?

#import

@interface CommonPageControl : UIPageControl

{

UIImage *activeImage;

UIImage *inactiveImage;

}

@end

#import "CommonPageControl.h"

@implementation CommonPageControl

- (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

// Initialization code

}

return self;

}

-(void)updateDots{

for(int i=0;i<[self.subviews count];i++){

if([(UIView *)[self.subviews objectAtIndex:i] isKindOfClass:[UIView class]]){//目前pageControl控件小點是一個view

UIView *dot=[self.subviews objectAtIndex:i];

if(i==self.currentPage){

dot.backgroundColor=[UIColor whiteColor];

}

else{

dot.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1];

}

}

}

}

//重寫基類方法

-(void)setCurrentPage:(NSInteger)currentPage{

[super setCurrentPage:currentPage];

[self updateDots];

}

@end

調(diào)用:

CGRect rect;

rect.origin.x = myScrollView.frame.origin.x;

rect.origin.y = self.frame.size.height-20;

rect.size.width = myScrollView.frame.size.width;

rect.size.height = 20;

myPagecontrol = [[CommonPageControl alloc] initWithFrame:rect];

myPagecontrol.userInteractionEnabled=NO;

[self.view addSubview:myPagecontrol];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容