Skip to content

Commit

Permalink
Merge pull request #14 from JNDisrupter/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jayelzaghmoutt authored Oct 16, 2022
2 parents 1070854 + d26eb9c commit dec5eba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion JNSegmentedControl.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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 {
Expand Down

0 comments on commit dec5eba

Please sign in to comment.