1. 改變:原來PageControl的subview是UIImageView,現在變成了UIView.

 

2. 解決辦法:重畫。

 

3. 代碼:(因為我的PageControl通過IB初始化的,所以下面的代碼中沒有初始化部分。你可以自行初始化)

01.//

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

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()