• 自义定UIPageControl


    @interface ZHPageControl : UIPageControl{
        
        UIImage *imagePageStateNormal;
        UIImage *imagePageStateHighlighted;
    }
    
    -
    (id)initWithFrame:(CGRect)frame;
    @property (nonatomic, retain) UIImage *imagePageStateNormal;
    @property (nonatomic, retain) UIImage *imagePageStateHighlighted;
    @end
    #import "ZHPageControl.h"
    
    /**
     *    @brief     声明一个私有方法, 该方法不允许对象直接使用
     *
     *    @param     private     <#private description#>
     *
     *    @return    <#return value description#>
     */
    @interface ZHPageControl(private)
    -(void)updateDots;
    @end
    @implementation ZHPageControl
    @synthesize imagePageStateNormal;
    @synthesize imagePageStateHighlighted;
    
    /**
     *    @brief    初始化
     *
     *    @param     frame     <#frame description#>
     *
     *    @return    <#return value description#>
     */
    - (id)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        return self;
    }
    
    /**
     *    @brief    设置正常状态点按钮的图片
     *
     *    @param     image     <#image description#>
     */
    - (void)setImagePageStateNormal:(UIImage *)image {
        [imagePageStateNormal release];
        imagePageStateNormal = [image retain];
        [self updateDots];
    }
    
    
    /**
     *    @brief    设置高亮状态点按钮图片
     *
     *    @param     image     <#image description#>
     */
    - (void)setImagePageStateHighlighted:(UIImage *)image { 
        [imagePageStateHighlighted release];
        imagePageStateHighlighted = [image retain];
        [self updateDots];
    }
    
    
    /**
     *    @brief    重写 setCurrentPage方法
     *
     *    @param     currentPage     当前页
     */
    - (void)setCurrentPage:(NSInteger)currentPage
    {
        [super setCurrentPage:currentPage];
        [self updateDots];
    }
    
    /**
     *    @brief    更新显示所有的点按钮
     */
    - (void)updateDots {
        if (imagePageStateNormal || imagePageStateHighlighted)
        {
            
            NSArray *subview = self.subviews;  // 获取所有子视图
            
            for (NSInteger i = 0; i < [subview count]; i++)
            {
                
            
            
                UIImageView *dot = [subview objectAtIndex:i];  // 以下不解释, 看了基本明白
                
                dot.image = self.currentPage == i ? imagePageStateNormal : imagePageStateHighlighted;
                
            }
        }
    }
    
    /**
     *    @brief     点击事件
     *
     *    @param     touch     <#touch description#>
     *    @param     event     <#event description#>
     */
    - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
        [super endTrackingWithTouch:touch withEvent:event];
        
        [self updateDots];
        
    }
    
    
    /**
     *    @brief    释放内存
     */
    - (void)dealloc {
        [imagePageStateNormal release], imagePageStateNormal = nil;
        [imagePageStateHighlighted release], imagePageStateHighlighted = nil;
        [super dealloc];
    }
    
    /**
     *    @brief    覆盖的drawRect:执行自定义绘制。
     *
     *    @param     rect     <#rect description#>
     */
    - (void)drawRect:(CGRect)rect
    {
        int count = [self.subviews count];
        int width=44;//自定义图标宽
        int height=44;//自定义图标高
        for (int i = 0; i < count; i++) {
            UIImageView* dot = [self.subviews objectAtIndex:i];
            [dot setFrame:CGRectMake(i*width, 0, width, height)];
            if (i == 0) {
                [dot setImage:imagePageStateHighlighted];
            }else {
                [dot setImage:imagePageStateNormal];
            }
        }
    }
    
    @end
  • 相关阅读:
    Dubbo源码分析系列---服务的发布
    Dubbo源码分析系列---扩展点加载
    Jdk动态代理和CGLIB动态代理大比拼
    定时任务的一些思路
    技术人的职业发展
    2017面试碎碎念
    Tiny Mapper
    RabbitMQ 简介
    Load Test Analyzer Overview
    2015 如期而至,你好
  • 原文地址:https://www.cnblogs.com/skyblue/p/3126684.html
Copyright © 2020-2023  润新知