Skip to content

Commit

Permalink
- fixed issue #1 (problem with height);
Browse files Browse the repository at this point in the history
- optimized image loading;
- examples updated with support dark mode;
  • Loading branch information
sh-khashimov committed Dec 20, 2019
1 parent 7b1f19f commit 995c50c
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Example/RESegmentedControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -35,6 +36,7 @@
2761BF3F2396C1310088F3EF /* BasicExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicExampleViewController.swift; sourceTree = "<group>"; };
2761BF402396C1310088F3EF /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
2761BF412396C1310088F3EF /* PresetsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresetsViewController.swift; sourceTree = "<group>"; };
27997225239BF8D60034BBA8 /* RESegmentedControlTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RESegmentedControlTests.swift; path = ../../Tests/RESegmentedControlTests/RESegmentedControlTests.swift; sourceTree = "<group>"; };
462BE5DA3480404C497B03F9 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
5C558C4879B21863C182B883 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* RESegmentedControl_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RESegmentedControl_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -144,6 +146,7 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
27997225239BF8D60034BBA8 /* RESegmentedControlTests.swift */,
607FACEB1AFB9204008FA782 /* Tests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
Expand Down Expand Up @@ -352,6 +355,7 @@
buildActionMask = 2147483647;
files = (
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */,
27997226239BF8D60034BBA8 /* RESegmentedControlTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 6 additions & 7 deletions Example/RESegmentedControl/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="a2d-ak-oDh">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="a2d-ak-oDh">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15509"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Example View Controller-->
<scene sceneID="Iww-wf-reH">
<objects>
<viewController id="7vo-ck-Eh0" customClass="ExampleViewController" customModule="OKSegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="7vo-ck-Eh0" customClass="ExampleViewController" customModule="RESegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="ULF-TL-D2a">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -64,7 +64,7 @@
<!--Presets View Controller-->
<scene sceneID="21c-ea-Zfe">
<objects>
<viewController id="5HL-TK-t5N" customClass="PresetsViewController" customModule="OKSegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="5HL-TK-t5N" customClass="PresetsViewController" customModule="RESegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="bBE-qF-rZF">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -262,7 +262,7 @@
<!--Basic Example View Controller-->
<scene sceneID="Wqs-8d-Yeq">
<objects>
<viewController id="tKk-6W-ts3" customClass="BasicExampleViewController" customModule="OKSegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="tKk-6W-ts3" customClass="BasicExampleViewController" customModule="RESegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="snX-ie-sMp">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -403,7 +403,7 @@
<!--Action View Controller-->
<scene sceneID="81o-wp-Sms">
<objects>
<viewController id="i1a-zR-yeP" customClass="ActionViewController" customModule="OKSegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="i1a-zR-yeP" customClass="ActionViewController" customModule="RESegmentedControl_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="btt-jJ-8qm">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -465,7 +465,6 @@
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Kpy-C1-Woy" firstAttribute="top" secondItem="PRu-Un-7Nt" secondAttribute="bottom" constant="30" id="A27-1H-fJd"/>
<constraint firstItem="Kpy-C1-Woy" firstAttribute="leading" secondItem="PVU-Lr-cH1" secondAttribute="leading" constant="10" id="X5f-IX-yXO"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
26 changes: 23 additions & 3 deletions Example/RESegmentedControl/PresetsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion RESegmentedControl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ internal class SegmentCollectionViewCell: UICollectionViewCell {
super.awakeFromNib()
self.contentView.backgroundColor = .clear
self.backgroundColor = .clear
item = nil
imageView.image = nil
imageDownload.cancel()
}

override func prepareForReuse() {
super.prepareForReuse()
imageView.image = nil
item = nil
imageDownload.cancel()
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/RESegmentedControl/Classes/RESegmentedControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()

Expand Down Expand Up @@ -181,6 +183,7 @@ open class RESegmentedControl: UIControl {
collectionViewBackground.addSubview(selectedBackgroundView)
self.addSubview(collectionView)
addLayouts()
updateCollectionViewSize(withItemSize: itemSize)
}

/// Adds layouts to the views.
Expand Down

0 comments on commit 995c50c

Please sign in to comment.