我想设置 UIPageControl
用图像代替点。我实现了以下代码,但它总是崩溃。请帮助我。
-(void)updateDots
{
for (int i=0; i<[_pageControl.subviews count]; i++) {
UIImageView *dot = [_pageControl.subviews objectAtIndex:i];
if (i==_pageControl.currentPage)
dot.image = [UIImage imageNamed:@"on.png"];
else
dot.image = [UIImage imageNamed:@"off.png"];
}
}
In iOS8,i got the following error *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x7f9dd9eaabb0'
最佳答案
您不应该假设 UIPageControl
将包含 UIImageViews
(它不包含)。
以下是使用公共(public) API 执行此操作的方法:
- (void)updateDots
{
// this only needs to be done one time
// 7x7 image (@1x)
_pageControl.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"on.png"]];
_pageControl.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"off.png"]];
}
关于ios - 如何在iOS8 Objective c中设置带有图像的UIPageControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32601857/