首页 > 代码库 > UiPaged的自定义
UiPaged的自定义
我们在写轮播图片时使用系统的控件往往无法满足项目需求,因此我们就开始自定义控件了。
以下是UIPageControl的自定义:
#import <UIKit/UIKit.h>
@interface UPage : UIPageControl
{
UIImage *_activeImage;//(当前页面所表示图片)
UIImage *_inactiveImage;//(当前界面外的图片)
}
@property(nonatomic,retain) UIImage *activeImage,*inactiveImage;
@end
#import "UPage.h"
@implementation UPage
@synthesize activeImage=_activeImage,inactiveImage=_inactiveImage;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
self.activeImage = [UIImage imageNamed:@"sy_da_sdd.png"];//(当前页面所表示图片)
self.inactiveImage = [UIImage imageNamed:@"sy_dt_sdde.png"];//(当前界面外的图片)
}
self.userInteractionEnabled=NO;
return self;
}
- (void)updateDots
{
for (int i = 0; i< [self.subviews count]; i++)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue]>= 7.0)
{
UIView *dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage)
{
dot.layer.backgroundColor=[UIColor clearColor].CGColor;
dot.layer.contents=(id)self.activeImage.CGImage;
}
else
{
dot.layer.backgroundColor=[UIColor clearColor].CGColor;
dot.layer.contents=(id)self.inactiveImage.CGImage;
}
}
else
{
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage)
{
dot.image = self.activeImage;
}
else
{
dot.image = self.inactiveImage;
}
}
}
}
- (void)setCurrentPage:(NSInteger)currentPage
{
[super setCurrentPage:currentPage];
[self updateDots];
}
@end
UiPaged的自定义