diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index c036ddf..c23bb6e 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 063AD5DA0C25B0AF16B0E21B3CD955F4 /* PinterestSegment-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = FF729ECB606D6BDB2B3F5DC07114785D /* PinterestSegment-dummy.m */; }; 17F2545D2017D07C206CB07E53485F6E /* PinterestSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = C111DFB3A0D234195E089302CBD5B637 /* PinterestSegment.swift */; }; 3384D28B7E0B9494AFA169A4BB543939 /* PinterestSegment-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 70323C329757501B884F0825B423231A /* PinterestSegment-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 443D924E27A6FC3500789E01 /* UIView+PinterestSegmentStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 443D924D27A6FC3500789E01 /* UIView+PinterestSegmentStyle.swift */; }; 4D5CF6A81F86D02AFFCBEA086305833F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A16F4CFC63FAC439D7A04994F579A03 /* Foundation.framework */; }; 7D3C3007AA9E2217DD3CD092B9ED88D2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A16F4CFC63FAC439D7A04994F579A03 /* Foundation.framework */; }; 86CA1852E566AB814EEE103143A7FB4D /* Pods-PinterestSegment_Example-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D0878928F6393A2476FE68468A02F32 /* Pods-PinterestSegment_Example-dummy.m */; }; @@ -32,6 +33,7 @@ 195BE62C3B66FF12E01CF62B5E3BD6CD /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 20EF4C8955A6E4544472F2928CB3A3DB /* PinterestSegment.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; path = PinterestSegment.podspec; sourceTree = ""; }; 3A35AC4BED155B8D5CB0257664170D1E /* PinterestSegment.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PinterestSegment.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 443D924D27A6FC3500789E01 /* UIView+PinterestSegmentStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+PinterestSegmentStyle.swift"; sourceTree = ""; }; 469C72798D9A18F3EA7E9E65254C4D8D /* PinterestSegment.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = PinterestSegment.xcconfig; sourceTree = ""; }; 5818CB693912F9BD9E37337977E748AF /* Pods-PinterestSegment_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-PinterestSegment_Example.release.xcconfig"; sourceTree = ""; }; 5A16F4CFC63FAC439D7A04994F579A03 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; @@ -86,6 +88,14 @@ path = "Example/Pods/Target Support Files/PinterestSegment"; sourceTree = ""; }; + 443D924C27A6FC2600789E01 /* Extension */ = { + isa = PBXGroup; + children = ( + 443D924D27A6FC3500789E01 /* UIView+PinterestSegmentStyle.swift */, + ); + path = Extension; + sourceTree = ""; + }; 558775936B62C63C81F628DD9A998FB7 /* Development Pods */ = { isa = PBXGroup; children = ( @@ -114,6 +124,7 @@ isa = PBXGroup; children = ( C111DFB3A0D234195E089302CBD5B637 /* PinterestSegment.swift */, + 443D924C27A6FC2600789E01 /* Extension */, B4D038931CFDC25EDFF0E2C7CAAB06ED /* Pod */, 13F422B391AD630E08C8BD6046303C78 /* Support Files */, ); @@ -254,6 +265,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 7DB346D0F39D3F0E887471402A8071AB; @@ -289,6 +301,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 443D924E27A6FC3500789E01 /* UIView+PinterestSegmentStyle.swift in Sources */, 063AD5DA0C25B0AF16B0E21B3CD955F4 /* PinterestSegment-dummy.m in Sources */, 17F2545D2017D07C206CB07E53485F6E /* PinterestSegment.swift in Sources */, ); diff --git a/Extension/UIView+PinterestSegmentStyle.swift b/Extension/UIView+PinterestSegmentStyle.swift new file mode 100644 index 0000000..bce0d90 --- /dev/null +++ b/Extension/UIView+PinterestSegmentStyle.swift @@ -0,0 +1,20 @@ +// +// UIView+PinterestSegmentStyle.swift +// PinterestSegment +// +// Created by Mariya Pankova on 30.01.2022. +// + +extension UIView { + public func setRadius(from style: PinterestSegmentStyle) { + clipsToBounds = true + switch style.radius { + case .rounded: + layer.cornerRadius = frame.height / 2 + case .roundedText: + layer.cornerRadius = (style.titleFont.lineHeight + style.titlePendingVertical) / 2 + case let .exact(value): + layer.cornerRadius = value + } + } +} diff --git a/PinterestSegment/PinterestSegment.swift b/PinterestSegment/PinterestSegment.swift index 3c8ae6c..910086e 100644 --- a/PinterestSegment/PinterestSegment.swift +++ b/PinterestSegment/PinterestSegment.swift @@ -9,7 +9,11 @@ import UIKit public struct PinterestSegmentStyle { - + public enum Radius { + case rounded + case roundedText + case exact(CGFloat) + } public var indicatorColor = UIColor(white: 0.95, alpha: 1) public var titleMargin: CGFloat = 16 public var titlePendingHorizontal: CGFloat = 14 @@ -20,6 +24,7 @@ public struct PinterestSegmentStyle { public var selectedBorderColor = UIColor.clear public var normalBorderColor = UIColor.clear public var minimumWidth: CGFloat? + public var radius: Radius = .roundedText public init() {} } @@ -275,7 +280,7 @@ public struct PinterestSegmentStyle { if style.normalBorderColor != .clear { backLabel.layer.borderColor = UIColor.darkGray.cgColor backLabel.layer.borderWidth = 2 - backLabel.layer.cornerRadius = backLabel.frame.size.height / 2 + backLabel.setRadius(from: style) } if let normalImage = item.normalImage { @@ -317,8 +322,8 @@ public struct PinterestSegmentStyle { let indRect = CGRect(x: coverX, y: coverY, width: coverW, height: coverH) setIndicatorFrame(indRect) - indicator.layer.cornerRadius = coverH/2 - selectedLabelsMaskView.layer.cornerRadius = coverH/2 + indicator.setRadius(from: style) + selectedLabelsMaskView.setRadius(from: style) let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PinterestSegment.handleTapGesture(_:))) addGestureRecognizer(tapGesture)