转载整理
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
|