From 995c50c2033ad121dab48f0ae3f29bcadcab36cc Mon Sep 17 00:00:00 2001 From: Sherzod Khashimov Date: Fri, 20 Dec 2019 10:59:35 +0500 Subject: [PATCH] - fixed issue #1 (problem with height); - optimized image loading; - examples updated with support dark mode; --- .../project.pbxproj | 4 +++ .../Base.lproj/Main.storyboard | 13 ++++----- .../darkBlack.colorset/Contents.json | 28 +++++++++++++++++++ .../PresetsViewController.swift | 26 +++++++++++++++-- README.md | 2 +- RESegmentedControl.podspec | 2 +- .../Cells/SegmentCollectionViewCell.swift | 2 ++ .../Classes/RESegmentedControl.swift | 3 ++ 8 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 Example/RESegmentedControl/Images.xcassets/darkBlack.colorset/Contents.json diff --git a/Example/RESegmentedControl.xcodeproj/project.pbxproj b/Example/RESegmentedControl.xcodeproj/project.pbxproj index 3b42b15..b4f5887 100644 --- a/Example/RESegmentedControl.xcodeproj/project.pbxproj +++ b/Example/RESegmentedControl.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 2761BF432396C1310088F3EF /* BasicExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2761BF3F2396C1310088F3EF /* BasicExampleViewController.swift */; }; 2761BF442396C1310088F3EF /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2761BF402396C1310088F3EF /* ExampleViewController.swift */; }; 2761BF452396C1310088F3EF /* PresetsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2761BF412396C1310088F3EF /* PresetsViewController.swift */; }; + 27997226239BF8D60034BBA8 /* RESegmentedControlTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27997225239BF8D60034BBA8 /* RESegmentedControlTests.swift */; }; 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; @@ -35,6 +36,7 @@ 2761BF3F2396C1310088F3EF /* BasicExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicExampleViewController.swift; sourceTree = ""; }; 2761BF402396C1310088F3EF /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = ""; }; 2761BF412396C1310088F3EF /* PresetsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresetsViewController.swift; sourceTree = ""; }; + 27997225239BF8D60034BBA8 /* RESegmentedControlTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RESegmentedControlTests.swift; path = ../../Tests/RESegmentedControlTests/RESegmentedControlTests.swift; sourceTree = ""; }; 462BE5DA3480404C497B03F9 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 5C558C4879B21863C182B883 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 607FACD01AFB9204008FA782 /* RESegmentedControl_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RESegmentedControl_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -144,6 +146,7 @@ 607FACE81AFB9204008FA782 /* Tests */ = { isa = PBXGroup; children = ( + 27997225239BF8D60034BBA8 /* RESegmentedControlTests.swift */, 607FACEB1AFB9204008FA782 /* Tests.swift */, 607FACE91AFB9204008FA782 /* Supporting Files */, ); @@ -352,6 +355,7 @@ buildActionMask = 2147483647; files = ( 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */, + 27997226239BF8D60034BBA8 /* RESegmentedControlTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/RESegmentedControl/Base.lproj/Main.storyboard b/Example/RESegmentedControl/Base.lproj/Main.storyboard index fd18ec6..7ef3d42 100644 --- a/Example/RESegmentedControl/Base.lproj/Main.storyboard +++ b/Example/RESegmentedControl/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -11,7 +11,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -262,7 +262,7 @@ - + @@ -403,7 +403,7 @@ - + @@ -465,7 +465,6 @@ - diff --git a/Example/RESegmentedControl/Images.xcassets/darkBlack.colorset/Contents.json b/Example/RESegmentedControl/Images.xcassets/darkBlack.colorset/Contents.json new file mode 100644 index 0000000..168c913 --- /dev/null +++ b/Example/RESegmentedControl/Images.xcassets/darkBlack.colorset/Contents.json @@ -0,0 +1,28 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "platform" : "ios", + "reference" : "darkTextColor" + } + }, + { + "idiom" : "universal", + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "platform" : "ios", + "reference" : "systemGray6Color" + } + } + ] +} \ No newline at end of file diff --git a/Example/RESegmentedControl/PresetsViewController.swift b/Example/RESegmentedControl/PresetsViewController.swift index e9d1e91..443783e 100644 --- a/Example/RESegmentedControl/PresetsViewController.swift +++ b/Example/RESegmentedControl/PresetsViewController.swift @@ -41,7 +41,13 @@ class PresetsViewController: UIViewController { @IBOutlet weak var customSimple1SegmentedControl: RESegmentedControl! { didSet { - var preset = BootstapPreset(backgroundColor: .black, selectedBackgroundColor: .darkGray, textColor: .lightGray, selectedTextColor: .white) + var backgroundColor: UIColor = .black + + if #available(iOS 11.0, *) { + backgroundColor = UIColor(named: "darkBlack") ?? .black + } + + var preset = BootstapPreset(backgroundColor: backgroundColor, selectedBackgroundColor: .darkGray, textColor: .lightGray, selectedTextColor: .white) preset.textFont = UIFont.systemFont(ofSize: 11, weight: .bold) preset.selectedTextFont = UIFont.systemFont(ofSize: 11, weight: .bold) @@ -68,7 +74,14 @@ class PresetsViewController: UIViewController { lazy var customSimple3preset: SegmentedControlPresettable = { - var preset = BootstapPreset(backgroundColor: .clear, selectedBackgroundColor: .black, textColor: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), selectedTextColor: .white) + + var selectedBackgroundColor: UIColor = .black + + if #available(iOS 11.0, *) { + selectedBackgroundColor = UIColor(named: "darkBlack") ?? .black + } + + var preset = BootstapPreset(backgroundColor: .clear, selectedBackgroundColor: selectedBackgroundColor, textColor: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), selectedTextColor: .white) preset.segmentBorderWidth = 2 preset.segmentBorderColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1) @@ -88,7 +101,14 @@ class PresetsViewController: UIViewController { @IBOutlet weak var customSimple4SegmentedControl: RESegmentedControl! { didSet { - var preset = BootstapPreset(backgroundColor: .clear, selectedBackgroundColor: #colorLiteral(red: 0.1960784346, green: 0.3411764801, blue: 0.1019607857, alpha: 1), textColor: .black, selectedTextColor: .white) + + var textColor: UIColor = .black + + if #available(iOS 13.0, *) { + textColor = .label + } + + var preset = BootstapPreset(backgroundColor: .clear, selectedBackgroundColor: #colorLiteral(red: 0.1960784346, green: 0.3411764801, blue: 0.1019607857, alpha: 1), textColor: textColor, selectedTextColor: .white) preset.segmentSpacing = 15 diff --git a/README.md b/README.md index 82d46a9..095253a 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ Pull requests are welcome. For major changes, please open an issue first to disc Please make sure to update tests as appropriate. -## Insparation +## Inspiration - [WWDC 2018: Adding Delight to your iOS App](https://developer.apple.com/videos/play/wwdc2018/233) diff --git a/RESegmentedControl.podspec b/RESegmentedControl.podspec index 2d7c774..06bde84 100644 --- a/RESegmentedControl.podspec +++ b/RESegmentedControl.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'RESegmentedControl' - s.version = '0.2.0' + s.version = '0.2.1' s.summary = 'A Customizable Segmented Control.' # This description is used to generate tags and improve search results. diff --git a/Sources/RESegmentedControl/Classes/Cells/SegmentCollectionViewCell.swift b/Sources/RESegmentedControl/Classes/Cells/SegmentCollectionViewCell.swift index eef501a..95233ff 100755 --- a/Sources/RESegmentedControl/Classes/Cells/SegmentCollectionViewCell.swift +++ b/Sources/RESegmentedControl/Classes/Cells/SegmentCollectionViewCell.swift @@ -52,6 +52,7 @@ internal class SegmentCollectionViewCell: UICollectionViewCell { super.awakeFromNib() self.contentView.backgroundColor = .clear self.backgroundColor = .clear + item = nil imageView.image = nil imageDownload.cancel() } @@ -59,6 +60,7 @@ internal class SegmentCollectionViewCell: UICollectionViewCell { override func prepareForReuse() { super.prepareForReuse() imageView.image = nil + item = nil imageDownload.cancel() } diff --git a/Sources/RESegmentedControl/Classes/RESegmentedControl.swift b/Sources/RESegmentedControl/Classes/RESegmentedControl.swift index 49068b6..a19730e 100755 --- a/Sources/RESegmentedControl/Classes/RESegmentedControl.swift +++ b/Sources/RESegmentedControl/Classes/RESegmentedControl.swift @@ -17,6 +17,8 @@ open class RESegmentedControl: UIControl { collectionViewFlow.sectionInset = .zero collectionViewFlow.scrollDirection = .horizontal collectionViewFlow.minimumInteritemSpacing = 0 + collectionViewFlow.minimumLineSpacing = 0 + collectionViewFlow.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) return collectionViewFlow }() @@ -181,6 +183,7 @@ open class RESegmentedControl: UIControl { collectionViewBackground.addSubview(selectedBackgroundView) self.addSubview(collectionView) addLayouts() + updateCollectionViewSize(withItemSize: itemSize) } /// Adds layouts to the views.