From 07c65f241158dcae4f2a4e32e56a1051a995ab58 Mon Sep 17 00:00:00 2001 From: mohammadsuhail98 Date: Mon, 9 Nov 2020 12:41:47 +0300 Subject: [PATCH] Fix changing page control image in main thread in iOS 14. --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Sources/FSPageControl.swift | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 FSPagerViewExamples.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/FSPagerViewExamples.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/FSPagerViewExamples.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/FSPagerViewExamples.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Sources/FSPageControl.swift b/Sources/FSPageControl.swift index e3bd745..0e5de62 100644 --- a/Sources/FSPageControl.swift +++ b/Sources/FSPageControl.swift @@ -245,10 +245,25 @@ open class FSPageControl: UIControl { let index = self.indicatorLayers.firstIndex(of: layer) let state: UIControl.State = index == self.currentPage ? .selected : .normal if let image = self.images[state] { + + let imageLayer = CALayer() + imageLayer.backgroundColor = UIColor.clear.cgColor + imageLayer.frame = CGRect(origin: CGPoint.zero, size: image.size) + imageLayer.contentsGravity = .resize + imageLayer.contents = image.cgImage + imageLayer.setNeedsLayout() + layer.strokeColor = nil - layer.fillColor = nil + layer.fillColor = UIColor(patternImage: image).cgColor layer.path = nil - layer.contents = image.cgImage + + for s in 0..<(layer.sublayers?.count ?? 0) { + if ((layer.sublayers?[s].isEqual(imageLayer)) != nil) { + layer.sublayers?[s].removeFromSuperlayer() + } + } + layer.addSublayer(imageLayer) + } else { layer.contents = nil let strokeColor = self.strokeColors[state]