是否有办法改变页面指示器的颜色 [英] Is there a way to change page indicator dots color
问题描述
我是新手的iphone编程,我想开发一个应用程序使用页面控制。我的视图的背景颜色是白色的,页面控制器默认一个也是白色的,这使得页面控制在我的视图中不可见,所以我改变了页面控件的背景颜色使其可见。现在,视图出现修补和坏。
提前感谢
我们自定义了UIPageControl为页面指示器使用自定义图像,我列出了类下面的内容...
GrayPageControl。 h
@interface GreyPageControl:UIPageControl
{
UIImage * activeImage;
UIImage * inactiveImage;
}
GrayPageControl.m
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
activeImage = [[UIImage imageNamed:@active_page_image.png] retain];
inactiveImage = [[UIImage imageNamed:@inactive_page_image.png] retain];
return self;
}
- (void)updateDots
{
for(int i = 0; i <[self.subviews count]; i ++)
{
UIImageView * dot = [self.subviews objectAtIndex:i];
if(i == self.currentPage)dot.image = activeImage;
else dot.image = inactiveImage;
}
}
- (void)setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
然后在View Controller中我们只是像正常的UIPageControl
IBOutlet GrayPageControl * PageIndicator;
编辑:
在具有GrayPageControl的视图控制器中,我有一个与GrayPageControl.ValueChanged事件相关联的IBAction。
(IBAction)pageChanged:(id)sender
{
int page = PageIndicator.currentPage;
//将滚动视图更新到适当的页面
CGRect frame = ImagesScroller.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[ImagesScroller scrollRectToVisible:frame animated:YES];
}
I am newbie to iphone programming, I am trying to develop an app which uses page control. My view's background color is white and page controllers default one is also white, which makes page control invisible on my view so I have changed the back ground color of page control to make is visible. Now, the view appears patched and bad. Is there a way to change just the dots color for page control?
Thanks in advance
解决方案We customized the UIPageControl to use a custom image for the page indicator, I have listed the guts of the class below...
GrayPageControl.h
@interface GrayPageControl : UIPageControl { UIImage* activeImage; UIImage* inactiveImage; }
GrayPageControl.m
-(id) initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; activeImage = [[UIImage imageNamed:@"active_page_image.png"] retain]; inactiveImage = [[UIImage imageNamed:@"inactive_page_image.png"] retain]; return self; } -(void) updateDots { for (int i = 0; i < [self.subviews count]; i++) { UIImageView* dot = [self.subviews objectAtIndex:i]; if (i == self.currentPage) dot.image = activeImage; else dot.image = inactiveImage; } } -(void) setCurrentPage:(NSInteger)page { [super setCurrentPage:page]; [self updateDots]; }
Then in the View Controller we just use it like a normal UIPageControl
IBOutlet GrayPageControl* PageIndicator;
Edit:
In the view controller that has the GrayPageControl I have an IBAction that is linked to the GrayPageControl.ValueChanged event.
-(IBAction) pageChanged:(id)sender { int page = PageIndicator.currentPage; // update the scroll view to the appropriate page CGRect frame = ImagesScroller.frame; frame.origin.x = frame.size.width * page; frame.origin.y = 0; [ImagesScroller scrollRectToVisible:frame animated:YES]; }
这篇关于是否有办法改变页面指示器的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!