我无法在 iOS 14 中设置页面控制点的边框颜色。以下代码适用于 iOS < 14,但不适用于 iOS 14:
for (int i = 0; i < [self.subViews count]; i++) {
UIView *dot = [self.subViews objectAtIndex:i];
dot.layer.borderWidth = 1;
dot.layer.borderColor = [UIColor blueColor].CGColor;
}
UIPageControl 色调颜色清晰。我只想添加边框。在 Obj-C 中需要一个解决方案。
最佳答案
评论
UIPageControl View 层次结构
iOS 13
iOS 14
新 API
即使您更新代码以匹配新的 View 层次结构......
UIView *pageControlContentView = self.pageControl.subviews[0];
UIView *pageControlIndicatorContentView = pageControlContentView.subviews[0];
[pageControlIndicatorContentView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.layer.borderWidth = 1;
obj.layer.borderColor = UIColor.blueColor.CGColor;
}];
...你会得到这样的东西:iOS 14 引入了可以使用的新属性和方法:
preferredIndicatorImage
setIndicatorImage(_:forPage:)
indicatorImageForPage:
您可以使用 SF 符号,例如:
UIImage *image = [UIImage systemImageNamed:@"link.circle.fill"];
self.pageControl.preferredIndicatorImage = image;
然后你会得到:换句话说,为了安全起见,避免私有(private) View 层次结构,使用
preferredIndicatorImage
.如果您想自定义图像等,您可以准备自己的图像。但这是另一个问题的主题。如果您想以编程方式进行,请搜索问题 like this one .由于您使用的是私有(private) View 层次结构,因此请学习您的工具(Xcode)并从 Examining the View Hierarchy 开始。和 Debugging View Hierarchies章节。下次您将能够找到自己的问题所在。
关于ios - UIPageControl 点边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63289401/