diff --git a/Example/Images/LICENSE b/Example/Images/LICENSE deleted file mode 100644 index e22d4e6..0000000 --- a/Example/Images/LICENSE +++ /dev/null @@ -1,3 +0,0 @@ -Author: Shared by @bytecodeminer -Link: https://wall.alphacoders.com/big.php?i=725422 -License: Images are for personal, non commercial use. \ No newline at end of file diff --git a/Example/SlidingSelector.xcodeproj/project.pbxproj b/Example/SlidingSelector.xcodeproj/project.pbxproj index 07c7863..67a87a3 100644 --- a/Example/SlidingSelector.xcodeproj/project.pbxproj +++ b/Example/SlidingSelector.xcodeproj/project.pbxproj @@ -3,30 +3,20 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ + 4A4415C02739C056003A7164 /* SlidingSelector in Frameworks */ = {isa = PBXBuildFile; productRef = 4A4415BF2739C056003A7164 /* SlidingSelector */; }; BE07996C22226B280013490D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE07996B22226B280013490D /* AppDelegate.swift */; }; BE07996E22226B280013490D /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE07996D22226B280013490D /* FirstViewController.swift */; }; BE07997322226B280013490D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BE07997122226B280013490D /* Main.storyboard */; }; BE07997522226B290013490D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BE07997422226B290013490D /* Assets.xcassets */; }; BE07997822226B290013490D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BE07997622226B290013490D /* LaunchScreen.storyboard */; }; - BE0799832222EA0B0013490D /* Earth.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5D9216A25560038609E /* Earth.jpg */; }; - BE0799842222EA0B0013490D /* Jupiter.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5D6216A25560038609E /* Jupiter.jpg */; }; - BE0799852222EA0B0013490D /* Mars.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5DD216A25560038609E /* Mars.jpg */; }; - BE0799862222EA0B0013490D /* Mercury.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5DA216A25560038609E /* Mercury.jpg */; }; - BE0799872222EA0B0013490D /* Neptune.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5DB216A25560038609E /* Neptune.jpg */; }; - BE0799882222EA0B0013490D /* Pluto.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5D8216A25560038609E /* Pluto.jpg */; }; - BE0799892222EA0B0013490D /* Saturn.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5D7216A25560038609E /* Saturn.jpg */; }; - BE07998A2222EA0B0013490D /* Uranus.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5DC216A25560038609E /* Uranus.jpg */; }; - BE07998B2222EA0B0013490D /* Venus.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BE82D5DE216A25570038609E /* Venus.jpg */; }; - BEA06A96249FDE8300D59C44 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BEA06A93249FDE8300D59C44 /* Media.xcassets */; }; - BEA06A97249FDE8300D59C44 /* SlidingSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEA06A94249FDE8300D59C44 /* SlidingSelectorView.swift */; }; - BEA06A98249FDE8300D59C44 /* SlidingSelectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEA06A95249FDE8300D59C44 /* SlidingSelectorViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4A4415BD2739C040003A7164 /* SlidingSelector */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SlidingSelector; path = ..; sourceTree = ""; }; BE07996922226B270013490D /* SlidingSelectorExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SlidingSelectorExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; BE07996B22226B280013490D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; BE07996D22226B280013490D /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = ""; }; @@ -34,18 +24,6 @@ BE07997422226B290013490D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; BE07997722226B290013490D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; BE07997922226B290013490D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - BE82D5D6216A25560038609E /* Jupiter.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Jupiter.jpg; sourceTree = ""; }; - BE82D5D7216A25560038609E /* Saturn.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Saturn.jpg; sourceTree = ""; }; - BE82D5D8216A25560038609E /* Pluto.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Pluto.jpg; sourceTree = ""; }; - BE82D5D9216A25560038609E /* Earth.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Earth.jpg; sourceTree = ""; }; - BE82D5DA216A25560038609E /* Mercury.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Mercury.jpg; sourceTree = ""; }; - BE82D5DB216A25560038609E /* Neptune.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Neptune.jpg; sourceTree = ""; }; - BE82D5DC216A25560038609E /* Uranus.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Uranus.jpg; sourceTree = ""; }; - BE82D5DD216A25560038609E /* Mars.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Mars.jpg; sourceTree = ""; }; - BE82D5DE216A25570038609E /* Venus.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = Venus.jpg; sourceTree = ""; }; - BEA06A93249FDE8300D59C44 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Media.xcassets; path = ../../Sources/Media.xcassets; sourceTree = ""; }; - BEA06A94249FDE8300D59C44 /* SlidingSelectorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SlidingSelectorView.swift; path = ../../Sources/SlidingSelectorView.swift; sourceTree = ""; }; - BEA06A95249FDE8300D59C44 /* SlidingSelectorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SlidingSelectorViewController.swift; path = ../../Sources/SlidingSelectorViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -53,12 +31,28 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4A4415C02739C056003A7164 /* SlidingSelector in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4A4415BC2739C040003A7164 /* Packages */ = { + isa = PBXGroup; + children = ( + 4A4415BD2739C040003A7164 /* SlidingSelector */, + ); + name = Packages; + sourceTree = ""; + }; + 4A4415BE2739C056003A7164 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; BE07996A22226B280013490D /* SlidingSelectorExample */ = { isa = PBXGroup; children = ( @@ -72,29 +66,13 @@ path = SlidingSelectorExample; sourceTree = ""; }; - BE1582B620E9624900C98D25 /* Images */ = { - isa = PBXGroup; - children = ( - BE82D5D9216A25560038609E /* Earth.jpg */, - BE82D5D6216A25560038609E /* Jupiter.jpg */, - BE82D5DD216A25560038609E /* Mars.jpg */, - BE82D5DA216A25560038609E /* Mercury.jpg */, - BE82D5DB216A25560038609E /* Neptune.jpg */, - BE82D5D8216A25560038609E /* Pluto.jpg */, - BE82D5D7216A25560038609E /* Saturn.jpg */, - BE82D5DC216A25560038609E /* Uranus.jpg */, - BE82D5DE216A25570038609E /* Venus.jpg */, - ); - path = Images; - sourceTree = ""; - }; BE2A061820E761FC00D771F6 = { isa = PBXGroup; children = ( - BEA06A92249FDE7600D59C44 /* SlidingSelector */, - BE1582B620E9624900C98D25 /* Images */, + 4A4415BC2739C040003A7164 /* Packages */, BE07996A22226B280013490D /* SlidingSelectorExample */, BE2A062220E761FC00D771F6 /* Products */, + 4A4415BE2739C056003A7164 /* Frameworks */, ); sourceTree = ""; }; @@ -106,16 +84,6 @@ name = Products; sourceTree = ""; }; - BEA06A92249FDE7600D59C44 /* SlidingSelector */ = { - isa = PBXGroup; - children = ( - BEA06A93249FDE8300D59C44 /* Media.xcassets */, - BEA06A94249FDE8300D59C44 /* SlidingSelectorView.swift */, - BEA06A95249FDE8300D59C44 /* SlidingSelectorViewController.swift */, - ); - path = SlidingSelector; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -133,6 +101,9 @@ dependencies = ( ); name = SlidingSelectorExample; + packageProductDependencies = ( + 4A4415BF2739C056003A7164 /* SlidingSelector */, + ); productName = GSSlidingSelectorSwift; productReference = BE07996922226B270013490D /* SlidingSelectorExample.app */; productType = "com.apple.product-type.application"; @@ -144,7 +115,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1000; - LastUpgradeCheck = 1010; + LastUpgradeCheck = 1310; ORGANIZATIONNAME = galarius; TargetAttributes = { BE07996822226B270013490D = { @@ -153,7 +124,7 @@ }; }; }; - buildConfigurationList = BE2A061C20E761FC00D771F6 /* Build configuration list for PBXProject "GSSlidingSelector" */; + buildConfigurationList = BE2A061C20E761FC00D771F6 /* Build configuration list for PBXProject "SlidingSelector" */; compatibilityVersion = "Xcode 9.3"; developmentRegion = en; hasScannedForEncodings = 0; @@ -176,19 +147,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - BE0799832222EA0B0013490D /* Earth.jpg in Resources */, - BE0799882222EA0B0013490D /* Pluto.jpg in Resources */, - BEA06A96249FDE8300D59C44 /* Media.xcassets in Resources */, BE07997822226B290013490D /* LaunchScreen.storyboard in Resources */, - BE0799852222EA0B0013490D /* Mars.jpg in Resources */, - BE0799862222EA0B0013490D /* Mercury.jpg in Resources */, - BE0799872222EA0B0013490D /* Neptune.jpg in Resources */, BE07997522226B290013490D /* Assets.xcassets in Resources */, - BE0799842222EA0B0013490D /* Jupiter.jpg in Resources */, - BE0799892222EA0B0013490D /* Saturn.jpg in Resources */, - BE07998B2222EA0B0013490D /* Venus.jpg in Resources */, BE07997322226B280013490D /* Main.storyboard in Resources */, - BE07998A2222EA0B0013490D /* Uranus.jpg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -220,9 +181,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - BEA06A98249FDE8300D59C44 /* SlidingSelectorViewController.swift in Sources */, BE07996C22226B280013490D /* AppDelegate.swift in Sources */, - BEA06A97249FDE8300D59C44 /* SlidingSelectorView.swift in Sources */, BE07996E22226B280013490D /* FirstViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -264,7 +223,7 @@ ); MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = ru.galarius.GSSlidingSelectorSwift; + PRODUCT_BUNDLE_IDENTIFIER = ru.galarius.SlidingSelectorExample; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; @@ -288,7 +247,7 @@ "@executable_path/Frameworks", ); MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = ru.galarius.GSSlidingSelectorSwift; + PRODUCT_BUNDLE_IDENTIFIER = ru.galarius.SlidingSelectorExample; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_COMPILATION_MODE = wholemodule; @@ -324,6 +283,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -349,7 +309,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -382,6 +342,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -401,7 +362,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; @@ -421,7 +382,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - BE2A061C20E761FC00D771F6 /* Build configuration list for PBXProject "GSSlidingSelector" */ = { + BE2A061C20E761FC00D771F6 /* Build configuration list for PBXProject "SlidingSelector" */ = { isa = XCConfigurationList; buildConfigurations = ( BE2A063820E761FE00D771F6 /* Debug */, @@ -431,6 +392,13 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 4A4415BF2739C056003A7164 /* SlidingSelector */ = { + isa = XCSwiftPackageProductDependency; + productName = SlidingSelector; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = BE2A061920E761FC00D771F6 /* Project object */; } diff --git a/Example/SlidingSelector.xcodeproj/xcshareddata/xcschemes/SlidingSelectorExample.xcscheme b/Example/SlidingSelector.xcodeproj/xcshareddata/xcschemes/SlidingSelectorExample.xcscheme index 9ad1707..c32d8a3 100644 --- a/Example/SlidingSelector.xcodeproj/xcshareddata/xcschemes/SlidingSelectorExample.xcscheme +++ b/Example/SlidingSelector.xcodeproj/xcshareddata/xcschemes/SlidingSelectorExample.xcscheme @@ -1,6 +1,6 @@ - + - + @@ -16,7 +16,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -38,6 +38,7 @@ + @@ -56,7 +57,6 @@ - @@ -67,7 +67,7 @@ - + @@ -95,5 +95,8 @@ + + + diff --git a/Example/SlidingSelectorExample/FirstViewController.swift b/Example/SlidingSelectorExample/FirstViewController.swift index 7bcbd15..b937e29 100644 --- a/Example/SlidingSelectorExample/FirstViewController.swift +++ b/Example/SlidingSelectorExample/FirstViewController.swift @@ -7,41 +7,38 @@ // import UIKit - -let GSDefaultSelectedIndex: Int = 3 // [1 - 7] -let GSTransformImageAnimationTime: TimeInterval = 0.4 +import SlidingSelector final class FirstViewController: UIViewController, SlidingSelectorDelegate { - @IBOutlet var selector: SlidingSelectorViewController! - - @IBOutlet var imgViewLeft: UIImageView! - @IBOutlet var imgViewSelected: UIImageView! - @IBOutlet var imgViewRight: UIImageView! - - var prevSelectedIndex: Int = 0 + @IBOutlet private var selector: SlidingSelectorViewController! + @IBOutlet private var imgViewLeft: UIImageView! + @IBOutlet private var imgViewSelected: UIImageView! + @IBOutlet private var imgViewRight: UIImageView! - var items = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"] + private var prevSelectedIndex = 3 + private let defaultSelectedIndex = 3 + private let animationTime: TimeInterval = 0.4 + private let items = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"] override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. + selector.items = items selector.delegate = self - selector.setSelectedIndex(GSDefaultSelectedIndex, animated: false) - prevSelectedIndex = GSDefaultSelectedIndex + selector.setSelectedIndex(defaultSelectedIndex, animated: false) // Set default images - imgViewLeft.image = imageFromIndex(GSDefaultSelectedIndex-1) - imgViewSelected.image = imageFromIndex(GSDefaultSelectedIndex) - imgViewRight.image = imageFromIndex(GSDefaultSelectedIndex+1) + imgViewLeft.image = imageFromIndex(defaultSelectedIndex - 1) + imgViewSelected.image = imageFromIndex(defaultSelectedIndex) + imgViewRight.image = imageFromIndex(defaultSelectedIndex + 1) view.backgroundColor = UIColor(red: 240/255.0, green: 235/255.0, blue: 180/255.0, alpha: 1.0) edgesForExtendedLayout = [] tabBarController?.tabBar.backgroundColor = view.backgroundColor } - override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { coordinator.animate(alongsideTransition: { _ in let orientation = UIApplication.shared.statusBarOrientation if orientation.isLandscape { @@ -58,20 +55,18 @@ final class FirstViewController: UIViewController, SlidingSelectorDelegate { super.viewWillTransition(to: size, with: coordinator) } - func imageFromIndex(_ index: Int) -> UIImage? { + private func imageFromIndex(_ index: Int) -> UIImage? { let name = items[index] return UIImage(named: "\(name).jpg") } - //NOTE: GSSlidingSelectorDelegate + // NOTE: - SlidingSelectorDelegate func slideSelector(_ selector: SlidingSelectorViewController!, didSelectItemAtIndex index: Int) { if index == prevSelectedIndex { return } - print("[GSSlidingSelectorViewController] Selected item at index: \(index) (\(items[index]))") - var prevImage: UIImage? var selectedImage: UIImage? var nextImage: UIImage? @@ -84,15 +79,15 @@ final class FirstViewController: UIViewController, SlidingSelectorDelegate { nextImage = imageFromIndex(index+1) } - UIView.transition(with: imgViewLeft, duration: GSTransformImageAnimationTime, options: .transitionFlipFromLeft, animations: { + UIView.transition(with: imgViewLeft, duration: animationTime, options: .transitionFlipFromLeft, animations: { self.imgViewLeft.image = prevImage }, completion: nil) - UIView.transition(with: imgViewSelected, duration: GSTransformImageAnimationTime, options: .transitionFlipFromLeft, animations: { + UIView.transition(with: imgViewSelected, duration: animationTime, options: .transitionFlipFromLeft, animations: { self.imgViewSelected.image = selectedImage }, completion: nil) - UIView.transition(with: imgViewRight, duration: GSTransformImageAnimationTime, options: .transitionFlipFromLeft, animations: { + UIView.transition(with: imgViewRight, duration: animationTime, options: .transitionFlipFromLeft, animations: { self.imgViewRight.image = nextImage }, completion: nil) diff --git a/Example/SlidingSelectorExample/Info.plist b/Example/SlidingSelectorExample/Info.plist index 017266f..4da5229 100644 --- a/Example/SlidingSelectorExample/Info.plist +++ b/Example/SlidingSelectorExample/Info.plist @@ -20,6 +20,11 @@ 1 LSRequiresIPhoneOS + UIAppFonts + + titilliumweb-semibold.ttf + titilliumweb-regular.ttf + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -44,11 +49,6 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIAppFonts - - titilliumweb-semibold.ttf - titilliumweb-regular.ttf - UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait diff --git a/Package.swift b/Package.swift index 0d9dcb6..47c7544 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.2 +// swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -10,7 +10,7 @@ let package = Package( // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "SlidingSelector", - targets: ["SlidingSelector"]), + targets: ["SlidingSelector"]) ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -21,6 +21,10 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "SlidingSelector", - path: "Sources"), + path: "Sources", + resources: [ + .process("Resources") + ] + ) ] ) diff --git a/ReadMe.md b/ReadMe.md index a6f5178..10d598b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -18,18 +18,16 @@ ## Installation -### Adding it to an existent iOS Project via Swift Package Manager +### Existing iOS Project 1. Using Xcode 11 go to File > Swift Packages > Add Package Dependency 2. Paste the project URL: https://github.com/Galarius/SlidingSelector.git -3. Click on next and select the project target -4. Drag & Drop `Sources/Media.xcassets` to `Copy Bundle Resources` section in `Build Phases` -4. Import `SlidingSelector` wherever needed +3. Import `SlidingSelector` ### Swift Package Manager ```swift -// swift-tools-version:5.1 +// swift-tools-version:5.3 import PackageDescription @@ -53,10 +51,6 @@ And then import wherever needed: `import SlidingSelector` The example project is located under `Example` folder. -![](./assets/setup.png) - -*SlidingSelector setup in the Interface Builder* - ## License 1. `SlidingSelector` is released under the MIT license. See [LICENSE](https://github.com/galarius/SlidingSelector/blob/master/LICENSE) for details. diff --git a/Sources/Media.xcassets/Contents.json b/Sources/Resources/Media.xcassets/Contents.json similarity index 100% rename from Sources/Media.xcassets/Contents.json rename to Sources/Resources/Media.xcassets/Contents.json diff --git a/Sources/Media.xcassets/swapLeft.imageset/Contents.json b/Sources/Resources/Media.xcassets/swapLeft.imageset/Contents.json similarity index 100% rename from Sources/Media.xcassets/swapLeft.imageset/Contents.json rename to Sources/Resources/Media.xcassets/swapLeft.imageset/Contents.json diff --git a/Sources/Media.xcassets/swapLeft.imageset/swap-left.pdf b/Sources/Resources/Media.xcassets/swapLeft.imageset/swap-left.pdf similarity index 100% rename from Sources/Media.xcassets/swapLeft.imageset/swap-left.pdf rename to Sources/Resources/Media.xcassets/swapLeft.imageset/swap-left.pdf diff --git a/Sources/Media.xcassets/swapRight.imageset/Contents.json b/Sources/Resources/Media.xcassets/swapRight.imageset/Contents.json similarity index 100% rename from Sources/Media.xcassets/swapRight.imageset/Contents.json rename to Sources/Resources/Media.xcassets/swapRight.imageset/Contents.json diff --git a/Sources/Media.xcassets/swapRight.imageset/swap-right.pdf b/Sources/Resources/Media.xcassets/swapRight.imageset/swap-right.pdf similarity index 100% rename from Sources/Media.xcassets/swapRight.imageset/swap-right.pdf rename to Sources/Resources/Media.xcassets/swapRight.imageset/swap-right.pdf diff --git a/Sources/SlidingSelectorView.swift b/Sources/SlidingSelectorView.swift index b47fae4..3ec1654 100644 --- a/Sources/SlidingSelectorView.swift +++ b/Sources/SlidingSelectorView.swift @@ -1,6 +1,6 @@ // // SlidingSelectorView.swift -// GSSlidingSelector +// SlidingSelector // // Created by galarius on 21.06.2020. // Copyright © 2020 galarius. All rights reserved. @@ -16,7 +16,7 @@ final public class SlidingSelectorView: UIView { } } public var font: UIFont? = UIFont(name: "Helvetica", size: UIFontDescriptor.preferredFontDescriptor(withTextStyle: .title2).pointSize) - + var isHelpHidden = false { didSet { imgViewLeft.isHidden = isHelpHidden @@ -27,8 +27,8 @@ final public class SlidingSelectorView: UIView { var scrollView = UIScrollView() private var labels = [UILabel]() - private var imgViewLeft = UIImageView(image: UIImage(named: "swapRight")) - private var imgViewRight = UIImageView(image: UIImage(named: "swapLeft")) + private var imgViewLeft = UIImageView(image: UIImage(named: "swapRight", in: .module, compatibleWith: nil)) + private var imgViewRight = UIImageView(image: UIImage(named: "swapLeft", in: .module, compatibleWith: nil)) private let transformTextFieldAnimationTime: TimeInterval = 0.15 private let highlightBackColorAnimationTime: TimeInterval = 0.05 @@ -88,15 +88,18 @@ final public class SlidingSelectorView: UIView { self.labels[index].transform = .identity }) } + func transformTextField(atIndex index: Int, animated: Bool) { UIView.animate(withDuration: animated ? transformTextFieldAnimationTime : 0, animations: { self.labels[index].transform = CGAffineTransform(scaleX: 0.5, y: 0.5) }) } + func scrollToIndex(_ index: Int, animated: Bool) { let target = CGPoint(x: CGFloat(index) * 0.5 * frame.width, y: 0.0) scrollView.setContentOffset(target, animated: animated) } + func toggleState(_ updating: Bool) { let duration = updating ? highlightBackColorAnimationTime : restoreBackColorAnimationTime let color = updating ? holdTouchColor : UIColor.clear @@ -106,17 +109,12 @@ final public class SlidingSelectorView: UIView { self.hideNeighbors(shouldHideNeighbors) }, completion: nil) } - func hideNeighbors(_ hidden: Bool) { - imgViewLeft.alpha = hidden ? 1.0 : 0.0 - imgViewRight.alpha = hidden ? 1.0 : 0.0 - for i in 0..<(labels.count) where i != selectedIndex { - labels[i].alpha = hidden ? 0.0 : 1.0 - } - } + func clearLabels() { scrollView.subviews.forEach { if $0 is UILabel { $0.removeFromSuperview() } } labels.removeAll() } + func addLabel(_ text: String) { let lbl = UILabel() lbl.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) @@ -129,4 +127,12 @@ final public class SlidingSelectorView: UIView { scrollView.addSubview(lbl) labels.append(lbl) } + + private func hideNeighbors(_ hidden: Bool) { + imgViewLeft.alpha = hidden ? 1.0 : 0.0 + imgViewRight.alpha = hidden ? 1.0 : 0.0 + for i in 0..<(labels.count) where i != selectedIndex { + labels[i].alpha = hidden ? 0.0 : 1.0 + } + } } diff --git a/Sources/SlidingSelectorViewController.swift b/Sources/SlidingSelectorViewController.swift index ade8c3b..a42192f 100644 --- a/Sources/SlidingSelectorViewController.swift +++ b/Sources/SlidingSelectorViewController.swift @@ -1,6 +1,6 @@ // // SlidingSelectorViewController.swift -// GSSlidingSelector +// SlidingSelector // // Created by galarius on 23.02.2019. // Copyright © 2019 galarius. All rights reserved. diff --git a/assets/setup.png b/assets/setup.png deleted file mode 100644 index a8e412e..0000000 Binary files a/assets/setup.png and /dev/null differ diff --git "a/assets/setup\302\240\342\200\224 \320\272\320\276\320\277\320\270\321\217.png" "b/assets/setup\302\240\342\200\224 \320\272\320\276\320\277\320\270\321\217.png" deleted file mode 100644 index da69f11..0000000 Binary files "a/assets/setup\302\240\342\200\224 \320\272\320\276\320\277\320\270\321\217.png" and /dev/null differ