Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIPageControl点边框颜色_Ios_Objective C - Fatal编程技术网

Ios UIPageControl点边框颜色

Ios UIPageControl点边框颜色,ios,objective-c,Ios,Objective C,我无法在iOS 14中设置页面控制点的边框颜色。以下代码适用于iOS

我无法在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中找到解决方案。

注释
  • iOS 14仍然是测试版,任何基于视图层次结构的解决方案都可以停止使用下一个测试版
  • 它也可以在任何未来的iOS版本(非测试版)中停止工作
  • 您依赖于私有视图层次结构。苹果可以随时更改,无需另行通知。low它属于私有API使用类别=您在这里只能靠自己
UIPageControl视图层次结构 iOS 13

iOS 14

新API 即使更新代码以匹配新的视图层次结构

UIView*pageControlContentView=self.pageControl.subview[0];
UIView*pageControlIndicatorContentView=pageControlContentView.subviews[0];
[pageControlIndicatorContentView.subviews enumerateObjectsUsingBlock:^(\uuuu-kindof UIView*\uu-Nonnull-obj,NSUInteger-idx,BOOL*\unonnull-stop){
obj.layer.borderWidth=1;
obj.layer.borderColor=UIColor.blueColor.CGColor;
}];
。。。你会得到这样的结果:

iOS 14引入了您可以使用的新属性和方法:

您可以使用SF符号,例如:

UIImage*image=[UIImage systemimagename:@“link.circle.fill”];
self.pageControl.preferredIndicatorImage=图像;
然后你会得到:

换句话说,为了安全起见,避免私有视图层次结构,请使用
preferredIndicatorImage
。如果你想定制自己的图片,你可以自己准备。但这是另一个问题的主题。如果您想以编程方式进行,请搜索问题

因为您使用的是私有视图层次结构,所以请学习您的工具(Xcode)并从和章节开始。下次你会发现自己出了什么问题。

评论
  • iOS 14仍然是测试版,任何基于视图层次结构的解决方案都可以停止使用下一个测试版
  • 它也可以在任何未来的iOS版本(非测试版)中停止工作
  • 您依赖于私有视图层次结构。苹果可以随时更改,无需另行通知。low它属于私有API使用类别=您在这里只能靠自己
UIPageControl视图层次结构 iOS 13

iOS 14

新API 即使更新代码以匹配新的视图层次结构

UIView*pageControlContentView=self.pageControl.subview[0];
UIView*pageControlIndicatorContentView=pageControlContentView.subviews[0];
[pageControlIndicatorContentView.subviews enumerateObjectsUsingBlock:^(\uuuu-kindof UIView*\uu-Nonnull-obj,NSUInteger-idx,BOOL*\unonnull-stop){
obj.layer.borderWidth=1;
obj.layer.borderColor=UIColor.blueColor.CGColor;
}];
。。。你会得到这样的结果:

iOS 14引入了您可以使用的新属性和方法:

您可以使用SF符号,例如:

UIImage*image=[UIImage systemimagename:@“link.circle.fill”];
self.pageControl.preferredIndicatorImage=图像;
然后你会得到:

换句话说,为了安全起见,避免私有视图层次结构,请使用
preferredIndicatorImage
。如果你想定制自己的图片,你可以自己准备。但这是另一个问题的主题。如果您想以编程方式进行,请搜索问题


因为您使用的是私有视图层次结构,所以请学习您的工具(Xcode)并从和章节开始。下次你会发现自己出了什么问题。

好吧,我只是觉得这像是“解决方案”

之前(

在(第14次监督检查)之后:


我只是觉得这像是“解决方案”

之前(

在(第14次监督检查)之后:

if #available(iOS 14.0, *) {
            pageControl.currentPageIndicatorTintColor = .blue // custom color
            pageControl.pageIndicatorTintColor = .blue.withAlphaComponent(0.3)
        } else {
            // Fallback on earlier versions
            for index: Int in 0...3 {
                guard pageControl.subviews.count > index else { return }
                let dot: UIView = pageControl.subviews[index]
                dot.layer.cornerRadius = dot.frame.size.height / 2
                if index == pageControl.currentPage {
                    dot.backgroundColor = .blue                        
                    dot.layer.borderWidth = 0
                } else {
                    dot.backgroundColor = UIColor.clear
                    dot.layer.borderColor = UIColor.blue.cgColor
                    dot.layer.borderWidth = 1
                }
            }
}