From 41acc40bedcf3c46c7845ce5dc7a3fcb1ee0c13f Mon Sep 17 00:00:00 2001 From: jayelzaghmoutt Date: Sun, 16 Oct 2022 09:45:42 +0300 Subject: [PATCH] - Fix the Height issue of badge count label in case the width is less than height - Update version to 1.0.6 --- JNSegmentedControl.podspec | 2 +- .../JNSegmentedCollectionView.swift | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/JNSegmentedControl.podspec b/JNSegmentedControl.podspec index fcd6609..2e4662c 100644 --- a/JNSegmentedControl.podspec +++ b/JNSegmentedControl.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "JNSegmentedControl" - s.version = "1.0.5" + s.version = "1.0.6" s.summary = "JNSegmentedControl is animated segmented control for iOS applications." s.description = "JNSegmentedControl is an easy to use, animated segmented control for iOS written in Swift. JNSegmentedControl supports 3 main styles of segments." s.homepage = "https://github.com/JNDisrupter" diff --git a/JNSegmentedControl/Classes/JNSegmentedCollectionView/JNSegmentedCollectionView.swift b/JNSegmentedControl/Classes/JNSegmentedCollectionView/JNSegmentedCollectionView.swift index f393c18..40274c1 100644 --- a/JNSegmentedControl/Classes/JNSegmentedCollectionView/JNSegmentedCollectionView.swift +++ b/JNSegmentedControl/Classes/JNSegmentedCollectionView/JNSegmentedCollectionView.swift @@ -352,14 +352,16 @@ public class JNSegmentedCollectionView: UIView { let defaultAttributedString = NSAttributedString(string: badgeString, attributes: [NSAttributedString.Key.font: option.badgeFont]) let defaultAttributedStringWidth = defaultAttributedString.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude , height: self.collectionView?.frame.height ?? 0.0), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).width + let defaultAttributedStringHeight = defaultAttributedString.boundingRect(with: CGSize(width: self.collectionView?.frame.width ?? 0.0 , height: CGFloat.greatestFiniteMagnitude ), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).height // Get width with selected attributes let selectedAttributedString = NSAttributedString(string: badgeString, attributes: [NSAttributedString.Key.font: option.selectedBadgeFont]) let selectedAttributedStringWidth = selectedAttributedString.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude , height: self.collectionView?.frame.height ?? 0.0), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).width + let selectedAttributedStringHeight = selectedAttributedString.boundingRect(with: CGSize(width: self.collectionView?.frame.width ?? 0.0 , height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).height // Get the maximum width from selected and unselected - maxmimumWidth = max(selectedAttributedStringWidth, defaultAttributedStringWidth) + maxmimumWidth = max(max(selectedAttributedStringWidth, selectedAttributedStringHeight), max(defaultAttributedStringWidth, defaultAttributedStringHeight)) case .multiple(let options): @@ -374,14 +376,15 @@ public class JNSegmentedCollectionView: UIView { // Get default attributed string width let defaultAttributedString = NSAttributedString(string: string, attributes: [NSAttributedString.Key.font: option.badgeFont]) let defaultAttributedStringWidth = defaultAttributedString.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude , height: self.collectionView?.frame.height ?? 0.0), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).width - + let defaultAttributedStringHeight = defaultAttributedString.boundingRect(with: CGSize(width: self.collectionView?.frame.width ?? 0.0 , height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).height // Get selected attributed string width let selectedAttributedString = NSAttributedString(string: string, attributes: [NSAttributedString.Key.font: option.selectedBadgeFont]) let selectedAttributedStringWidth = selectedAttributedString.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude , height: self.collectionView?.frame.height ?? 0.0), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).width + let selectedAttributedStringHeight = selectedAttributedString.boundingRect(with: CGSize(width: self.collectionView?.frame.width ?? 0.0 , height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).height // Get max - let itemMaxWidth = max(selectedAttributedStringWidth, defaultAttributedStringWidth) + let itemMaxWidth = max(max(selectedAttributedStringWidth, selectedAttributedStringHeight), max(defaultAttributedStringWidth, defaultAttributedStringHeight)) // Compare it to current maximum if itemMaxWidth > maxmimumWidth {