ios - 如何在iOS8 Objective c中设置带有图像的UIPageControl?

标签 ios objective-c iphone xcode6 uipagecontrol

我想设置 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/

相关文章:

iOS UIWebView loadHTMLString 不起作用

ios - UICollectionView 自定义单元格并进行水平滚动

ios - Facebook 和键盘动画管理

ios - UICollectionView 单元格水平对齐而不是垂直对齐以模仿跳板?

c++ - .mm 转换导致 Undefined symbols for architecture i386 错误

iphone - Facebook loginViewFetchedUserInfo 被调用两次

iphone - 在 UIPageViewController 中禁用/启用滚动

iphone - 在 Objective C 中生成 SHA256 字符串

iphone - 使用 UIGestureRecognizer 和点击操作进行幻灯片放映

iphone - Objective C 方法和语法