UIPageControl基本用法


转载整理


pageControl = [ [ [ UIPageControl alloc ] init ] autorelease ] ;
pageControl . numberOfPages = pageNum ;
pageControl . pageIndicatorTintColor = [ UIColor darkGrayColor ] ;
pageControl . currentPageIndicatorTintColor = [ UIColor whiteColor ] ;
pageControl . frame = CGRectMake ( 0 , CGRectGetMaxY ( self . bounds ) - 30 ,
                               CGRectGetWidth ( self . bounds ) , 20 ) ;
[ self addSubview :pageControl ] ;
huv

图片更换

1. 改变:原来PageControl的subview是UIImageView,现在变成了UIView.

2. 解决办法:重画。

3. 代码:(因为我的PageControl通过IB初始化的,所以下面的代码中没有初始化部分。你可以自行初始化

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
//  CustomPageControl.m
//  Sampling
//
//  Created by Megan on 10/18/13.
//  Copyright (c) 2013. All rights reserved.
//
 
#import "CustomPageControl.h"
 
@implementation CustomPageControl
 
- ( void )setCurrentPage:(NSInteger)currentPage
{
     [super setCurrentPage:currentPage];
     [self setNeedsDisplay];   
}
 
- ( void )setNumberOfPages:(NSInteger)numberOfPages
{
     [super setNumberOfPages:numberOfPages];
     
      [self setNeedsDisplay];
     
}
 
- ( void )drawRect:(CGRect)iRect
{
     int i;
     CGRect rect;
     UIImage *image;
     
     iRect = self.bounds;
     
     if (self.opaque) {
         [self.backgroundColor set];
         UIRectFill(iRect);
     }
     
     UIImage *_activeImage = [UIImage imageNamed:@ "INDICATOR-activated.png" ];
     UIImage *_inactiveImage = [UIImage imageNamed:@ "INDICATOR-deactivated.png" ];
     CGFloat _kSpacing = 5.0f;
     
     if (self.hidesForSinglePage && self.numberOfPages == 1) {
         return ;
     }
     
     rect.size.height = _activeImage.size.height;
     rect.size.width = self.numberOfPages * _activeImage.size.width + (self.numberOfPages - 1) * _kSpacing;
     rect.origin.x = floorf((iRect.size.width - rect.size.width) / 2.0);
     rect.origin.y = floorf((iRect.size.height - rect.size.height) / 2.0);
     rect.size.width = _activeImage.size.width;
     
     for (i = 0; i < self.numberOfPages; ++i) {
         image = (i == self.currentPage) ? _activeImage : _inactiveImage;
         [image drawInRect:rect];
         rect.origin.x += _activeImage.size.width + _kSpacing;
     }
}
 
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值