gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:39:18 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com