diff --git a/TopTabBarView.xcodeproj/project.pbxproj b/TopTabBarView.xcodeproj/project.pbxproj new file mode 100644 index 0000000..3d937c3 --- /dev/null +++ b/TopTabBarView.xcodeproj/project.pbxproj @@ -0,0 +1,382 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 63703BEA2829366E008F4ABC /* TopTabBarView.docc in Sources */ = {isa = PBXBuildFile; fileRef = 63703BE92829366E008F4ABC /* TopTabBarView.docc */; }; + 63703BEB2829366E008F4ABC /* TopTabBarView.h in Headers */ = {isa = PBXBuildFile; fileRef = 63703BE82829366E008F4ABC /* TopTabBarView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 63703C32282940C6008F4ABC /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63703C2E282940C6008F4ABC /* UIView+Extension.swift */; }; + 63703C33282940C6008F4ABC /* TopTabbarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63703C2F282940C6008F4ABC /* TopTabbarView.swift */; }; + 63703C34282940C6008F4ABC /* CircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63703C30282940C6008F4ABC /* CircleView.swift */; }; + 63703C35282940C6008F4ABC /* TabBarCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63703C31282940C6008F4ABC /* TabBarCollectionView.swift */; }; + 63703C38282940CE008F4ABC /* demo.mov in Resources */ = {isa = PBXBuildFile; fileRef = 63703C37282940CE008F4ABC /* demo.mov */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 63703BE52829366E008F4ABC /* TopTabBarView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TopTabBarView.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 63703BE82829366E008F4ABC /* TopTabBarView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TopTabBarView.h; sourceTree = ""; }; + 63703BE92829366E008F4ABC /* TopTabBarView.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = TopTabBarView.docc; sourceTree = ""; }; + 63703C2E282940C6008F4ABC /* UIView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = ""; }; + 63703C2F282940C6008F4ABC /* TopTabbarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopTabbarView.swift; sourceTree = ""; }; + 63703C30282940C6008F4ABC /* CircleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CircleView.swift; sourceTree = ""; }; + 63703C31282940C6008F4ABC /* TabBarCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarCollectionView.swift; sourceTree = ""; }; + 63703C37282940CE008F4ABC /* demo.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = demo.mov; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 63703BE22829366E008F4ABC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 63703BDB2829366E008F4ABC = { + isa = PBXGroup; + children = ( + 63703BE72829366E008F4ABC /* TopTabBarView */, + 63703BE62829366E008F4ABC /* Products */, + ); + sourceTree = ""; + }; + 63703BE62829366E008F4ABC /* Products */ = { + isa = PBXGroup; + children = ( + 63703BE52829366E008F4ABC /* TopTabBarView.framework */, + ); + name = Products; + sourceTree = ""; + }; + 63703BE72829366E008F4ABC /* TopTabBarView */ = { + isa = PBXGroup; + children = ( + 63703C36282940CE008F4ABC /* Media */, + 63703BE82829366E008F4ABC /* TopTabBarView.h */, + 63703BE92829366E008F4ABC /* TopTabBarView.docc */, + 63703C2D282940C6008F4ABC /* Source */, + ); + path = TopTabBarView; + sourceTree = ""; + }; + 63703C2D282940C6008F4ABC /* Source */ = { + isa = PBXGroup; + children = ( + 63703C2E282940C6008F4ABC /* UIView+Extension.swift */, + 63703C2F282940C6008F4ABC /* TopTabbarView.swift */, + 63703C30282940C6008F4ABC /* CircleView.swift */, + 63703C31282940C6008F4ABC /* TabBarCollectionView.swift */, + ); + path = Source; + sourceTree = ""; + }; + 63703C36282940CE008F4ABC /* Media */ = { + isa = PBXGroup; + children = ( + 63703C37282940CE008F4ABC /* demo.mov */, + ); + path = Media; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 63703BE02829366E008F4ABC /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 63703BEB2829366E008F4ABC /* TopTabBarView.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 63703BE42829366E008F4ABC /* TopTabBarView */ = { + isa = PBXNativeTarget; + buildConfigurationList = 63703BEE2829366E008F4ABC /* Build configuration list for PBXNativeTarget "TopTabBarView" */; + buildPhases = ( + 63703BE02829366E008F4ABC /* Headers */, + 63703BE12829366E008F4ABC /* Sources */, + 63703BE22829366E008F4ABC /* Frameworks */, + 63703BE32829366E008F4ABC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = TopTabBarView; + productName = TopTabBarView; + productReference = 63703BE52829366E008F4ABC /* TopTabBarView.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 63703BDC2829366E008F4ABC /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastUpgradeCheck = 1320; + TargetAttributes = { + 63703BE42829366E008F4ABC = { + CreatedOnToolsVersion = 13.2.1; + }; + }; + }; + buildConfigurationList = 63703BDF2829366E008F4ABC /* Build configuration list for PBXProject "TopTabBarView" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 63703BDB2829366E008F4ABC; + productRefGroup = 63703BE62829366E008F4ABC /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 63703BE42829366E008F4ABC /* TopTabBarView */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 63703BE32829366E008F4ABC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 63703C38282940CE008F4ABC /* demo.mov in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 63703BE12829366E008F4ABC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 63703C35282940C6008F4ABC /* TabBarCollectionView.swift in Sources */, + 63703C33282940C6008F4ABC /* TopTabbarView.swift in Sources */, + 63703C34282940C6008F4ABC /* CircleView.swift in Sources */, + 63703C32282940C6008F4ABC /* UIView+Extension.swift in Sources */, + 63703BEA2829366E008F4ABC /* TopTabBarView.docc in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 63703BEC2829366E008F4ABC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + 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; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 63703BED2829366E008F4ABC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + 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; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 63703BEF2829366E008F4ABC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Mindinventory.TopTabBarView; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = 1; + }; + name = Debug; + }; + 63703BF02829366E008F4ABC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Mindinventory.TopTabBarView; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = 1; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 63703BDF2829366E008F4ABC /* Build configuration list for PBXProject "TopTabBarView" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 63703BEC2829366E008F4ABC /* Debug */, + 63703BED2829366E008F4ABC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 63703BEE2829366E008F4ABC /* Build configuration list for PBXNativeTarget "TopTabBarView" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 63703BEF2829366E008F4ABC /* Debug */, + 63703BF02829366E008F4ABC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 63703BDC2829366E008F4ABC /* Project object */; +} diff --git a/TopTabBarView.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/TopTabBarView.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/TopTabBarView.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/TopTabBarView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TopTabBarView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/TopTabBarView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/TopTabBarView/Media/demo.mov b/TopTabBarView/Media/demo.mov new file mode 100644 index 0000000..36e4864 Binary files /dev/null and b/TopTabBarView/Media/demo.mov differ diff --git a/TopTabBarView/Source/CircleView.swift b/TopTabBarView/Source/CircleView.swift new file mode 100644 index 0000000..50a0de7 --- /dev/null +++ b/TopTabBarView/Source/CircleView.swift @@ -0,0 +1,29 @@ +// +// CircleView.swift +// CustomTopBarDemo +// +// Created by Parth Gohel on 06/05/22. +// + +import Foundation +import UIKit + +final class CircleView: UIView { + + private let circleShapeLayer = CAShapeLayer() + + var fillColor: UIColor = .red + + override func draw(_ rect: CGRect) { + super.draw(rect) + drawCircle() + } + + func drawCircle() { + let bezierPath = UIBezierPath() + bezierPath.addArc(withCenter: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2), radius: self.frame.size.height/2, startAngle: 0, endAngle: 360, clockwise: true) + circleShapeLayer.path = bezierPath.cgPath + circleShapeLayer.fillColor = fillColor.cgColor + self.layer.insertSublayer(circleShapeLayer, at: 0) + } +} diff --git a/TopTabBarView/Source/TabBarCollectionView.swift b/TopTabBarView/Source/TabBarCollectionView.swift new file mode 100644 index 0000000..551a7e2 --- /dev/null +++ b/TopTabBarView/Source/TabBarCollectionView.swift @@ -0,0 +1,218 @@ +// +// CustomTabBar.swift +// CustomTopBarDemo +// +// Created by Parth Gohel on 06/05/22. +// + +import Foundation +import UIKit + +public class TabBarCollectionView: UICollectionView { + + /// Fill color of back wave layer + var layerFillColor: UIColor { + get { + return UIColor(cgColor: kLayerFillColor) + } + set{ + kLayerFillColor = newValue.cgColor + backgroundColor = newValue + } + } + + var numberOfItem: Int = 0 + + /// Wave Height + var waveHeight: CGFloat { + get{ + return self.minimalHeight + } + set{ + self.minimalHeight = newValue + } + } + + var numberOfTabItem: Int { + get { + return numberOfItem + } set { + numberOfItem = newValue + } + } + + var dotColor: UIColor = .red { + didSet { + circlePoint.fillColor = dotColor + } + } + internal var minimalHeight: CGFloat = 18 + private var kLayerFillColor: CGColor = UIColor.red.cgColor + private var displayLink: CADisplayLink! + private let tabBarShapeLayer = CAShapeLayer() + private var minimalY: CGFloat { + get { + return -minimalHeight + } + } + var animating = false { + didSet { + self.isUserInteractionEnabled = !animating + self.displayLink?.isPaused = !animating + } + } + + /// Controll point of wave + + private var leftPoint4 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + leftPoint4.backgroundColor = .clear + } + } + private var leftPoint3 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + leftPoint3.backgroundColor = .clear + } + } + private var leftPoint2 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + leftPoint2.backgroundColor = .clear + } + } + private var leftPoint1 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + leftPoint1.backgroundColor = .clear + } + } + private var centerPoint1 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + centerPoint1.backgroundColor = .clear + } + } + private var centerPoint2 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + centerPoint2.backgroundColor = .clear + } + } + private var rightPoint1 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + rightPoint1.backgroundColor = .clear + } + } + private var rightPoint2 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + rightPoint2.backgroundColor = .clear + } + } + private var rightPoint4 = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + rightPoint4.backgroundColor = .clear + } + } + private var circlePoint = CircleView(frame: CGRect(x: 0.0, y: 0.0, width: 8, height: 8)) { + didSet { + circlePoint.backgroundColor = .clear + } + } + + /// Draws the receiver’s image within the passed-in rectangle. + /// + /// - Parameter rect: rect of view + override public func draw(_ rect: CGRect) { + super.draw(rect) + self.setupTabBar() + } +} + +// MARK: - Setup Tabbar +extension TabBarCollectionView { + + func setupTabBar() { + + guard numberOfItem != 0 else { return } + clipsToBounds = false + addSubview(leftPoint4) + addSubview(leftPoint3) + addSubview(leftPoint2) + addSubview(leftPoint1) + addSubview(centerPoint1) + addSubview(centerPoint2) + addSubview(rightPoint1) + addSubview(rightPoint2) + addSubview(rightPoint4) + addSubview(circlePoint) + displayLink = CADisplayLink(target: self, selector: #selector(updateShapeLayer)) + displayLink?.add(to: RunLoop.main, forMode: RunLoop.Mode.default) + displayLink?.isPaused = true + tabBarShapeLayer.fillColor = kLayerFillColor + layer.insertSublayer(tabBarShapeLayer, at: 0) + update(with: 1) + updateShapeLayer() + } + + func update(with index: Int) { + guard numberOfItem != 0 + else { return } + let width = (self.bounds.width)/CGFloat(numberOfItem) + let changeValue = (width*(CGFloat(index)))-(width/2) + setDefaultlayoutControlPoints(waveHeight: minimalHeight, locationX: changeValue) + } +} + +// MARK: - Set layer path +extension TabBarCollectionView { + + func setDefaultlayoutControlPoints(waveHeight: CGFloat, locationX: CGFloat) { + + let width = (bounds.width/CGFloat(numberOfItem)) + leftPoint4.center = CGPoint(x: 0, y: bounds.maxY) + rightPoint4.center = CGPoint(x: bounds.width, y: bounds.maxY) + + let imaganaeryFram = CGRect(x: locationX-(width/2), y: self.bounds.maxY + minimalHeight , width: width, height: minimalHeight) + + leftPoint3.center = CGPoint(x: imaganaeryFram.minX - width/2, y: self.bounds.maxY) + + let topOffset: CGFloat = imaganaeryFram.width / 4.3 + let bottomOffset: CGFloat = imaganaeryFram.width / 4.5 + + leftPoint2.center = CGPoint(x: imaganaeryFram.midX, y: imaganaeryFram.minY) + leftPoint1.center = CGPoint(x: imaganaeryFram.minX + bottomOffset, y: self.bounds.maxY) + centerPoint1.center = CGPoint(x: imaganaeryFram.midX - topOffset - 8, y: imaganaeryFram.minY) + centerPoint2.center = CGPoint(x: imaganaeryFram.maxX + width/2, y: self.bounds.maxY) + rightPoint1.center = CGPoint(x: imaganaeryFram.midX + topOffset + 8, y: imaganaeryFram.minY) + rightPoint2.center = CGPoint(x: imaganaeryFram.maxX - bottomOffset, y: self.bounds.maxY) + circlePoint.center = CGPoint(x: leftPoint2.center.x, y: self.bounds.maxY) + } + + /// updateShapeLayer + @objc func updateShapeLayer() { + tabBarShapeLayer.path = getCurrentPath() + } + + /// Get path + /// + /// - Returns: get current index path + func getCurrentPath() -> CGPath { + + let bezierPath = UIBezierPath() + bezierPath.move(to: CGPoint(x: 0.0, y: self.bounds.height)) + bezierPath.addLine(to: CGPoint(x: 0.0, y: leftPoint4.viewCenter(usePresentationLayerIfPossible: animating).y)) + bezierPath.addLine(to: leftPoint3.viewCenter(usePresentationLayerIfPossible: animating)) + bezierPath.addCurve( + to: leftPoint2.viewCenter(usePresentationLayerIfPossible: animating), + controlPoint1: leftPoint1.viewCenter(usePresentationLayerIfPossible: animating), + controlPoint2: centerPoint1.viewCenter(usePresentationLayerIfPossible: animating) + ) + bezierPath.addCurve( + to: centerPoint2.viewCenter(usePresentationLayerIfPossible: animating), + controlPoint1: rightPoint1.viewCenter(usePresentationLayerIfPossible: animating), + controlPoint2: rightPoint2.viewCenter(usePresentationLayerIfPossible: animating) + ) + bezierPath.addLine(to: leftPoint3.viewCenter(usePresentationLayerIfPossible: animating)) + bezierPath.addLine(to: rightPoint4.viewCenter(usePresentationLayerIfPossible: animating)) + bezierPath.addLine(to: CGPoint(x: self.bounds.width, y: self.bounds.height)) + bezierPath.close() + return bezierPath.cgPath + + } +} diff --git a/TopTabBarView/Source/TopTabbarView.swift b/TopTabBarView/Source/TopTabbarView.swift new file mode 100644 index 0000000..5765672 --- /dev/null +++ b/TopTabBarView/Source/TopTabbarView.swift @@ -0,0 +1,245 @@ +// +// TopTabbarView.swift +// CustomTopBarDemo +// +// Created by Parth Gohel on 09/05/22. +// + +import Foundation +import UIKit + +final class ItemCollectionViewCell: UICollectionViewCell { + + var tabbarTitleLabel: UILabel = UILabel(frame: .zero) + + override init(frame : CGRect) { + super.init(frame : frame) + loadTitleLabel() + configureLabel() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + } + + override func awakeFromNib() { + super.awakeFromNib() + backgroundColor = .clear + } + + private func loadTitleLabel() { + + tabbarTitleLabel.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(tabbarTitleLabel) + NSLayoutConstraint.activate([ + tabbarTitleLabel.topAnchor.constraint(equalTo: contentView.topAnchor), + tabbarTitleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + tabbarTitleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + tabbarTitleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + ]) + } + + private func configureLabel() { + tabbarTitleLabel.textAlignment = .center + } + + func configure(with title: String) { + tabbarTitleLabel.text = title + } + + func configureStyle( + font: UIFont = UIFont.boldSystemFont(ofSize: 18), + foregroundColor: UIColor = .white + ){ + tabbarTitleLabel.font = font + tabbarTitleLabel.textColor = foregroundColor + } +} + +public enum TabBarItemStyle { + case setStyle(font:UIFont, foregroundColor: UIColor) + case none +} + +public class TopTabbarView: UIView { + + public var collectionView: TabBarCollectionView = TabBarCollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout.init()) + + public var dataSource: [String] = [] { + didSet { + collectionView.numberOfTabItem = dataSource.count + } + } + + public var dotColor: UIColor = .red { + didSet { + collectionView.dotColor = dotColor + } + } + + /// Wave Height + public var waveHeight: CGFloat = 20 { + didSet { + collectionView.waveHeight = waveHeight + } + } + + public var leftPadding: CGFloat = 50 { + didSet { + leadingConstraint?.constant = leftPadding + } + } + + public var tabBarColor: UIColor = .systemBlue { + didSet { + collectionView.layerFillColor = tabBarColor + contentView.backgroundColor = tabBarColor + backgroundColor = .clear + (collectionView.cellForItem(at: [0,0]) as? ItemCollectionViewCell)?.tabbarTitleLabel.textColor = .red + } + } + + public var rightPadding: CGFloat = 50 { + didSet { + trailingConstraint?.constant = -rightPadding + } + } + public var tabBarItemStyle: TabBarItemStyle = .none { + didSet { + collectionView.reloadData() + } + } + + public var isScaleItem: Bool = true + public var onItemSelected: ((Int) -> Void)? + var leadingConstraint: NSLayoutConstraint? + var trailingConstraint: NSLayoutConstraint? + var contentView: UIView = UIView(frame: .zero) + + private var priviousSelectedIndex: Int = -1 + + public override func awakeFromNib() { + super.awakeFromNib() + loadCollectionView() + loadContentView() + configureCollectionView() + } +} + +extension TopTabbarView { + + private func loadContentView() { + + contentView.translatesAutoresizingMaskIntoConstraints = false + addSubview(contentView) + NSLayoutConstraint.activate([ + contentView.topAnchor.constraint(equalTo: topAnchor, constant: 0), + contentView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -collectionView.minimalHeight), + contentView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0), + contentView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0), + ]) + + contentView.backgroundColor = .orange + contentView.superview?.sendSubviewToBack(contentView) + } + + private func loadCollectionView() { + + collectionView.translatesAutoresizingMaskIntoConstraints = false + addSubview(collectionView) + leadingConstraint = collectionView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: leftPadding) + trailingConstraint = collectionView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -rightPadding) + NSLayoutConstraint.activate([ + collectionView.topAnchor.constraint(equalTo: topAnchor, constant: 0), + collectionView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -collectionView.minimalHeight), + leadingConstraint!, + trailingConstraint!, + ]) + + collectionView.register(ItemCollectionViewCell.self, forCellWithReuseIdentifier: "ItemCollectionViewCell") + } + + private func configureCollectionView() { + + let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() + layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + layout.minimumInteritemSpacing = 0 + layout.minimumLineSpacing = 0 + collectionView.setCollectionViewLayout(layout, animated: true) + collectionView.delegate = self + collectionView.dataSource = self + collectionView.layerFillColor = tabBarColor + contentView.backgroundColor = tabBarColor + collectionView.numberOfTabItem = dataSource.count + } + + private func performSpringAnimation(for cell: ItemCollectionViewCell, index: Int) { + UIView.animate(withDuration: 0.9, delay: 0.0, usingSpringWithDamping: 0.57, initialSpringVelocity: 0.0, options: [], animations: { () -> Void in + self.collectionView.update(with: index) + + }, completion: { _ in + self.collectionView.animating = false + }) + UIView.animate(withDuration: 0.9, delay: 0.0, usingSpringWithDamping: 0.57, initialSpringVelocity: 0.0, options: .curveEaseInOut, animations: { + if self.isScaleItem { + cell.tabbarTitleLabel.transform = CGAffineTransform.init(scaleX: 1.5, y: 1.5) + } + }, completion: nil) + } +} + +extension TopTabbarView: UICollectionViewDelegate, + UICollectionViewDataSource, + UICollectionViewDelegateFlowLayout { + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + dataSource.count + } + + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCollectionViewCell", for: indexPath) as? ItemCollectionViewCell + else { return UICollectionViewCell() } + cell.configure(with: dataSource[indexPath.row]) + switch tabBarItemStyle { + case .setStyle(let font, let foreground): + cell.configureStyle(font: font, foregroundColor: foreground) + case .none: break + } + return cell + } + + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: (collectionView.frame.size.width)/CGFloat(dataSource.count), height: collectionView.bounds.size.height) + } + + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + + guard let cell = collectionView.cellForItem(at: indexPath) as? ItemCollectionViewCell + else { return } + onItemSelected?(indexPath.row) + if indexPath.row != self.priviousSelectedIndex { + + (collectionView as? TabBarCollectionView)?.animating = true + + let orderedTabBarItemViews: [UIView] = { + let interactionViews = collectionView.subviews.filter({ $0 is ItemCollectionViewCell }) + return interactionViews.sorted(by: { $0.frame.minX < $1.frame.minX }) + }() + + orderedTabBarItemViews.forEach({ (objectView) in + let objectIndex = orderedTabBarItemViews.firstIndex(of: objectView) + if indexPath.row == objectIndex {} + else if objectIndex == priviousSelectedIndex { + guard let cell = collectionView.cellForItem(at: [0, priviousSelectedIndex]) as? ItemCollectionViewCell + else { return } + UIView.animate(withDuration: 0.9, delay: 0.0, usingSpringWithDamping: 0.57, initialSpringVelocity: 0.0, options: .curveEaseInOut, animations: { + if self.isScaleItem { + cell.tabbarTitleLabel.transform = CGAffineTransform.init(scaleX: 1, y: 1) + } + }, completion: nil) + } + }) + priviousSelectedIndex = indexPath.row + performSpringAnimation(for: cell, index: indexPath.row+1) + } + } +} diff --git a/TopTabBarView/Source/UIView+Extension.swift b/TopTabBarView/Source/UIView+Extension.swift new file mode 100644 index 0000000..bc97ffd --- /dev/null +++ b/TopTabBarView/Source/UIView+Extension.swift @@ -0,0 +1,18 @@ +// +// UIView+Extension.swift +// CustomTopBarDemo +// +// Created by Parth Gohel on 06/05/22. +// + +import UIKit + +extension UIView { + + func viewCenter(usePresentationLayerIfPossible: Bool) -> CGPoint { + if usePresentationLayerIfPossible, let presentationLayer = layer.presentation() { + return presentationLayer.position + } + return center + } +} diff --git a/TopTabBarView/TopTabBarView.docc/TopTabBarView.md b/TopTabBarView/TopTabBarView.docc/TopTabBarView.md new file mode 100755 index 0000000..3005d39 --- /dev/null +++ b/TopTabBarView/TopTabBarView.docc/TopTabBarView.md @@ -0,0 +1,13 @@ +# ``TopTabBarView`` + +Summary + +## Overview + +Text + +## Topics + +### Group + +- ``Symbol`` \ No newline at end of file diff --git a/TopTabBarView/TopTabBarView.h b/TopTabBarView/TopTabBarView.h new file mode 100644 index 0000000..9b91d69 --- /dev/null +++ b/TopTabBarView/TopTabBarView.h @@ -0,0 +1,18 @@ +// +// TopTabBarView.h +// TopTabBarView +// +// Created by mac-0009 on 09/05/22. +// + +#import + +//! Project version number for TopTabBarView. +FOUNDATION_EXPORT double TopTabBarViewVersionNumber; + +//! Project version string for TopTabBarView. +FOUNDATION_EXPORT const unsigned char TopTabBarViewVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + +