iphone开发之自定义UIPageControl小图标

自定义一个pageControl继承于UIpageControl。具体代码如下:

//
//  CloPageControl.h
//  lvYe
//
//  Created by Cloay on 12-8-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CloPageControl : UIPageControl{
    UIImage *activeImage;
    UIImage *inActiveIamge;
}

@end

实现方法:

//
//  CloPageControl.m
//  lvYe
//
//  Created by Cloay on 12-8-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CloPageControl.h"

@implementation CloPageControl

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    activeImage = [UIImage imageNamed:@"icon_star"];
    inActiveIamge = [UIImage imageNamed:@"icon_dot"];
    
    int count = [self.subviews count];
    for (int i = 0; i < count; i++) {
        UIImageView* dot = [self.subviews objectAtIndex:i];
        [dot setFrame:CGRectMake(i*15, 0, 15, 15)];
        if (i == 0) {
            [dot setImage:activeImage];
        }else {
            [dot setImage:inActiveIamge];            
        }
    }
}

- (void)setCurrentPage:(NSInteger)currentPage{
    [super setCurrentPage:currentPage];
    [self updateDots];
}

- (void)updateDots{
    for (int i = 0; i < [self.subviews count]; i++)
    {
        UIImageView* dot = [self.subviews objectAtIndex:i];
        if (i == self.currentPage) dot.image = activeImage;
        else dot.image = inActiveIamge;
    }
}

@end




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值