2011-01-07 130 views
2

http://apptech.next-munich.com/2010/04/customizing-uipagecontrols-looks.html如何从默认白色更改Pagecontroller指标颜色?

在上面的网址针对定制UIPageControl的外貌......

在我的应用程序的一些示例代码,我想改变的PageControl指示器(点)颜色一些其他颜色的,而不是默认的白色.. 。我按照以上链接提供的代码。但是,我有疑问。

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

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

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

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

感谢

回答

4

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

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

我用这两个图像:

Active image为活动点

Inactive image非活动点

编辑

如果要修改的尺寸点,也许

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 */); 
} 

应该这样做。

+0

非常感谢你Jilouc ...它工作得很好... – kanmani 2011-01-07 13:01:14