2

http://apptech.next-munich.com/2010/04/customizing-uipagecontrols-looks.html

在上面的 url 中有一些用于自定义 UIPageControl 外观的示例代码...

在我的应用程序中,我想将 pagecontrol 指示器(点)颜色更改为其他颜色,而不是默认的白色...我正在按照上面链接中给出的代码进行操作。但是,我有疑问。

NSString* imgActive = [[NSBundlemainBundle] pathForResource:IMG_PAGE_ACTIVE ofType:nil];

NSString* imgInactive = [[NSBundlemainBundle] pathForResource:IMG_PAGE_INACTIVE ofType:nil];

我应该为 pathForResource 提供什么:-------------。以及我应该在哪里添加活动和非活动页面的图像以及如何将图像检索到应用程序中。

请给我一些想法来做到这一点......

提前致谢

4

1 回答 1

4

只需将这两个图像添加到您的项目资源中。例如dot_active.pngdot_inactive.png

NSString* imgActive = [[NSBundlemainBundle] pathForResource:@"dot_active" ofType:@"png"];
NSString* imgInactive = [[NSBundlemainBundle] pathForResource:@"dot_inactive" ofType:@"png"];

我使用这两个图像:

活动图像对于活动点

非活动图像对于不活跃的点

编辑

如果你想修改点的大小,也许

for (NSUIntegersubviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) {
    UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
    if (subviewIndex == page) {
        [subview setImage:[UIImage imageWithContentsOfFile:imgActive]];
    } else {
        [subview setImage:[UIImage imageWithContentsOfFile:imgInactive]];
    }
    subview.frame = CGRectMake(/* position and dimensions you need */);
}

应该做的伎俩。

于 2011-01-07T12:46:54.467 回答