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;

    就是这么简单

  • 相关阅读:
    Git本地操作2
    Blast在windows下的使用过程
    和为T
    出现次数最多的整数
    蓝桥杯 未名湖边的烦恼 java
    蓝桥杯数字三角形 java
    ①①将线性拉伸
    ⑩把线型对象转平面对象
    ⑨矩形
    ⑧建立样条:(样条也能够被拉伸)
  • 原文地址:https://www.cnblogs.com/wengzilin/p/3210331.html
Copyright © 2011-2022 走看看