diff --git a/BonMot.podspec b/BonMot.podspec index 210f546a..68dfdb9e 100644 --- a/BonMot.podspec +++ b/BonMot.podspec @@ -10,7 +10,8 @@ Pod::Spec.new do |s| s.license = 'MIT' s.author = { "Zev Eisenberg" => "zev@zeveisenberg.com" } s.source = { :git => "https://github.com/Rightpoint/BonMot.git", :tag => s.version.to_s } - s.social_media_url = 'https://twitter.com/ZevEisenberg' + # Setting the twitter url is causing builds to fail due to not being able to reach twitter. + # s.social_media_url = 'https://twitter.com/ZevEisenberg' s.requires_arc = true s.ios.deployment_target = '11.0' diff --git a/Sources/UIKit/AdaptableTextContainer.swift b/Sources/UIKit/AdaptableTextContainer.swift index 791f35d5..4958bc97 100644 --- a/Sources/UIKit/AdaptableTextContainer.swift +++ b/Sources/UIKit/AdaptableTextContainer.swift @@ -117,13 +117,8 @@ extension UISegmentedControl { // `UISegmentedControl` has terrible generics ([NSObject: AnyObject]? or [AnyHashable: Any]?) on /// `titleTextAttributes`, so use a helper in Swift 3+ - @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes { - let attributes = titleTextAttributes(for: state) ?? [:] - var result: StyleAttributes = [:] - for value in attributes { - result[value.key] = value - } - return result + @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes? { + titleTextAttributes(for: state) } /// Adapt `attributedTitle`, for all control states, to the specified trait collection. @@ -132,7 +127,7 @@ extension UISegmentedControl { @objc(bon_updateTextForTraitCollection:) public func adaptText(forTraitCollection traitCollection: UITraitCollection) { for state in UIControl.State.commonStates { - let attributes = bon_titleTextAttributes(for: state) + guard let attributes = bon_titleTextAttributes(for: state) else { continue } let newAttributes = NSAttributedString.adapt(attributes: attributes, to: traitCollection) setTitleTextAttributes(newAttributes, for: state) } diff --git a/Tests/UIKitBonMotTests.swift b/Tests/UIKitBonMotTests.swift index 44f5b65f..d8ca6db8 100644 --- a/Tests/UIKitBonMotTests.swift +++ b/Tests/UIKitBonMotTests.swift @@ -120,7 +120,30 @@ class UIKitBonMotTests: XCTestCase { } } - func writeTestSegmentedControl() {} + func testSegmentedControl() { + let segmentedControl = UISegmentedControl() + // Make sure the test is valid and the title text attributes are not defined for the normal state + XCTAssertNil(segmentedControl.titleTextAttributes(for: .normal)) + + segmentedControl.insertSegment(withTitle: ".", at: 0, animated: false) + + // Assign the title text attributes for the normal state and ensure original values match + segmentedControl.setTitleTextAttributes(adaptiveStyle.attributes, for: .normal) + + var attributes = segmentedControl.titleTextAttributes(for: .normal) + XCTAssertEqual(attributes?[.font] as? UIFont, expectedFont) + BONAssertColor(inAttributes: attributes, key: .foregroundColor, color: adaptiveStyle.color!) + BONAssert(attributes: attributes, query: { $0.pointSize }, float: expectedFont.pointSize) + + // Update the trait collection and ensure the font grows. + if #available(iOS 10.0, tvOS 10.0, *) { + segmentedControl.adaptText(forTraitCollection: UITraitCollection(preferredContentSizeCategory: UIContentSizeCategory.extraLarge)) + attributes = segmentedControl.titleTextAttributes(for: .normal) + BONAssert(attributes: attributes, query: { $0.pointSize }, float: expectedFont.pointSize + 2) + BONAssertColor(inAttributes: attributes, key: .foregroundColor, color: adaptiveStyle.color!) + } + } + func writeTestNavigationBar() {} func writeTestToolbar() {} func writeTestViewController() {}