zoukankan      html  css  js  c++  java
  • 自义定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
  • 相关阅读:
    oracle的安装与plsql的环境配置
    Working with MSDTC
    soapui-java.lang.Exception Failed to load url
    Oracle 一个owner访问另一个owner的table,不加owner
    Call API relation to TLS 1.2
    Call API HTTP header Authorization: Basic
    VS2008 .csproj cannot be opened.The project type is not supported by this installat
    The changes couldn't be completed.Please reboot your computer and try again.
    Create DB Table View Procedure
    DB Change
  • 原文地址:https://www.cnblogs.com/skyblue/p/3126684.html
Copyright © 2011-2022 走看看