zoukankan      html  css  js  c++  java
  • 【原】自定义UIPageControl的圆点

    在下面的两种情况下会导致圆点贴图刷新:

    1.用户调用setCurrentPage:(NSInteger)currentPage时
    所以重载这个函数便可拦截
    2.点击圆点矩形区域时
    [转载]UIPageControl <wbr>圆点颜色的改变
     
     
    这说明,我们可以通过重载setCurrentPage方法来进行拦截
    源码如下:
    1 MyPageControl.h:
    2 #import <Foundation/Foundation.h>
    3 @interface MyPageControl : UIPageControl
    4 {
    5     UIImage* activeImage;
    6     UIImage* inactiveImage;
    7 }
    8 @end
     1 MyPageControl.m:
     2 #import "MyPageControl.h"
     3 @implementation GrayPageControl
     4 
     5 -(id) initWithFrame:(CGRect)frame
     6 {
     7 self = [super initWithFrame:frame];
     8 activeImage = [[UIImage imageNamed:@"RedPoint.png"] retain];
     9     inactiveImage = [[UIImage imageNamed:@"BluePoint.png"] retain];
    10     return self;
    11 }
    12 -(void) updateDots
    13 {
    14     for (int i = 0; i < [self.subviews count]; i++)
    15     {
    16         UIImageView* dot = [self.subviews objectAtIndex:i];
    17         if (i == self.currentPage) dot.image = activeImage;
    18         else dot.image = inactiveImage;
    19     }
    20 }
    21 -(void) setCurrentPage:(NSInteger)page
    22 {
    23     [super setCurrentPage:page];
    24     [self updateDots];
    25 }
    26 @end

    调用:

    pageControl = [[GrayPageControl alloc] initWithFrame:CGRectMake(0.0, 460.0 - (96 + 48) / 2, 320.0, 48.0 /2)];
    pageControl.userInteractionEnabled = NO;

    就是这么简单

  • 相关阅读:
    Docker Private Registry
    Dockerfile
    docker存储卷
    392. 判断子序列
    1576. 替换所有的问号
    270. 最接近的二叉搜索树值
    292. Nim 游戏
    680. 验证回文字符串 Ⅱ
    876. 链表的中间结点
    543. 二叉树的直径
  • 原文地址:https://www.cnblogs.com/wengzilin/p/3210331.html
Copyright © 2011-2022 走看看