From 7b8ffa653934a9c4a970ace7b921ddd5589ef5ab Mon Sep 17 00:00:00 2001 From: Berdikhan Satenov Date: Mon, 12 Oct 2020 16:42:36 +0800 Subject: [PATCH] XCode 12 compatibility --- FPageControl.podspec | 2 +- FPageControl/FPageControl.m | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/FPageControl.podspec b/FPageControl.podspec index 0c6ed3a..1f659af 100644 --- a/FPageControl.podspec +++ b/FPageControl.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FPageControl' - s.version = '0.6.0' + s.version = '0.7.0' s.summary = 'Custom Page Control for Fave' s.description = <<-DESC diff --git a/FPageControl/FPageControl.m b/FPageControl/FPageControl.m index f436f3e..34f2038 100644 --- a/FPageControl/FPageControl.m +++ b/FPageControl/FPageControl.m @@ -44,11 +44,19 @@ -(void)prepareForInterfaceBuilder { -(void)layoutSubviews { [super layoutSubviews]; + NSArray *subViews = self.subviews; + CGFloat mainWidth = self.frame.size.width; + CGFloat mainHeight = self.frame.size.height; + if (@available(iOS 14.0, *)) { + subViews = self.subviews.firstObject.subviews.firstObject.subviews; + mainWidth = self.subviews.firstObject.subviews.firstObject.frame.size.width; + mainHeight = self.subviews.firstObject.subviews.firstObject.frame.size.height; + } NSInteger i = 0; - CGFloat width = self.dotSize * (CGFloat)(self.subviews.count + 3) + self.dotSpacing * (CGFloat)(self.subviews.count - 1); - CGFloat x = self.frame.size.width / 2 - (width / 2); - CGFloat y = self.frame.size.height / 2 - self.dotSize / 2; - for (UIView *view in self.subviews) { + CGFloat width = self.dotSize * (CGFloat)(subViews.count + 3) + self.dotSpacing * (CGFloat)(subViews.count - 1); + CGFloat x = mainWidth / 2 - (width / 2); + CGFloat y = mainHeight / 2 - self.dotSize / 2; + for (UIView *view in subViews) { CGRect frame = view.frame; frame.origin.x = x; frame.origin.y = y; @@ -59,10 +67,19 @@ -(void)layoutSubviews { frame.size = CGSizeMake(self.dotSize, self.dotSize); x += self.dotSize + self.dotSpacing; } + if (@available(iOS 14.0, *)) { + ((UIImageView*)view).image = nil; + if (self.currentPage == i) { + view.backgroundColor = self.currentPageIndicatorTintColor; + } else { + view.backgroundColor = self.pageIndicatorTintColor; + } + } view.layer.cornerRadius = self.dotSize / 2; view.frame = frame; i += 1; } + } @end