自定义UIPageController

简单粗暴,直接贴代码

-(id) initWithFrame:(CGRect)frame {    

self = [super initWithFrame:frame];    

_activeImage = [UIImage imageNamed:@"home_banner_pagecontrol_active"];    

_unActiveImage = [UIImage imageNamed:@"home_banner_pagecontrol_unactive"];    

return self;

}

-(void) updateDots {       

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

    //圆点        

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

//添加imageView      

  if ([dot.subviews count] == 0) {          

  UIImageView * view = [[UIImageView alloc]initWithFrame:dot.bounds];          

  [dot addSubview:view];      

  };                 

UIImageView * view = dot.subviews[0];                 

if (i==self.currentPage) {          

  view.image=self.activeImage;            

[view setFrame:CGRectMake(0, 0, kImageWith-1, kImageHeight - 1)];            

dot.backgroundColor = [UIColor clearColor];        

}else {            

view.image=self.unActiveImage;            

[view setFrame:CGRectMake(0, 0, kImageHeight, kImageHeight)];            

dot.backgroundColor = [UIColor clearColor];      

  }    

}  

} -(void)setCurrentPage:(NSInteger)page {    

[super setCurrentPage:page];  

  [self updateDots];

}

其中,setCurrentPage 是UIPageController的set方法

你可能感兴趣的:(自定义UIPageController)