转:自定义UIPageControl的indicator的image

转:自定义UIPageControl的indicator的image

创建:2012.03.01
转:来自F。
===CustomPageControl.h===

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>


@interface CustomPageControl : UIPageControl {

    UIImage* imageNormal;

    UIImage* imageCurrent;

}


@property (nonatomic, retain) UIImage* imageNormal;

@property (nonatomic, retain) UIImage* imageCurrent;

@end

===CustomPageControl.m===

#import "CustomPageControl.h"


@interface CustomPageControl(Private)

- (void) updateDots;

@end


@implementation CustomPageControl

@synthesize imageNormal,imageCurrent;



/** override to update dots */

- (void) setCurrentPage:(NSInteger)currentPage

{

    [super setCurrentPage:currentPage];

    

    // update dot views

    [self updateDots];

}


/** override to update dots */

- (void) updateCurrentPageDisplay

{

    [super updateCurrentPageDisplay];

    

    // update dot views

    [self updateDots];

}


/** Override setImageNormal */

- (void) setImageNormal:(UIImage*)image

{

    [imageNormal release];

    imageNormal = [image retain];

    

    // update dot views

    [self updateDots];

}


/** Override setImageCurrent */

- (void) setImageCurrent:(UIImage*)image

{

    [imageCurrent release];

    imageCurrent = [image retain];

    

    // update dot views

    [self updateDots];

}


- (void) endTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event 

{

    [super endTrackingWithTouch:touch withEvent:event];

    

    [self updateDots];

}


#pragma mark -

#pragma mark updateDots


- (void) updateDots

{

    if(imageNormal || imageCurrent)

    {

        // Get subviews

        NSArray* dotViews = self.subviews;

        for(int i = 0; i < dotViews.count; ++i)

        {

            UIImageView* dot = [dotViews objectAtIndex:i];

            // Set image

            dot.image = (i == self.currentPage) ? imageCurrent : imageNormal;

        }

    }

}

#pragma mark-

#pragma mark dealloc

- (void) dealloc

{

    [imageNormal release];

    imageNormal = nil;

    [imageCurrent release];

    imageCurrent = nil;

    

[super dealloc];

}


@end

+++++

你可能感兴趣的:(转:自定义UIPageControl的indicator的image)