From 3caf201a9f91fccdd63c2d78188a590c00e36f0a Mon Sep 17 00:00:00 2001 From: Ivan <6350992+bivant@users.noreply.github.com> Date: Wed, 24 Sep 2025 13:36:57 +0300 Subject: [PATCH 1/2] Add option to omit image for the TitleImage segmented control item (set empty string in normalImageInfos/selectedImageInfos) --- .../JXSegmentedTitleImageDataSource.swift | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/Sources/TitleImage/JXSegmentedTitleImageDataSource.swift b/Sources/TitleImage/JXSegmentedTitleImageDataSource.swift index eb28c46..4ce4480 100644 --- a/Sources/TitleImage/JXSegmentedTitleImageDataSource.swift +++ b/Sources/TitleImage/JXSegmentedTitleImageDataSource.swift @@ -66,7 +66,7 @@ open class JXSegmentedTitleImageDataSource: JXSegmentedTitleDataSource { open override func preferredSegmentedView(_ segmentedView: JXSegmentedView, widthForItemAt index: Int) -> CGFloat { var width = super.preferredSegmentedView(segmentedView, widthForItemAt: index) - if itemWidth == JXSegmentedViewAutomaticDimension { + if itemWidth == JXSegmentedViewAutomaticDimension, hasImage(for: index) { switch titleImageType { case .leftImage, .rightImage: width += titleImageSpacing + imageSize.width @@ -85,28 +85,37 @@ open class JXSegmentedTitleImageDataSource: JXSegmentedTitleDataSource { public override func segmentedView(_ segmentedView: JXSegmentedView, widthForItemContentAt index: Int) -> CGFloat { var width = super.segmentedView(segmentedView, widthForItemContentAt: index) - switch titleImageType { - case .leftImage, .rightImage: - width += titleImageSpacing + imageSize.width - case .topImage, .bottomImage: - width = max(width, imageSize.width) - case .onlyImage: - width = imageSize.width - case .onlyTitle: - break - case .backgroundImage: - width = max(width, imageSize.width) + if hasImage(for: index) { + switch titleImageType { + case .leftImage, .rightImage: + width += titleImageSpacing + imageSize.width + case .topImage, .bottomImage: + width = max(width, imageSize.width) + case .onlyImage: + width = imageSize.width + case .onlyTitle: + break + case .backgroundImage: + width = max(width, imageSize.width) + } } return width } //MARK: - JXSegmentedViewDataSource open override func registerCellClass(in segmentedView: JXSegmentedView) { - segmentedView.collectionView.register(JXSegmentedTitleImageCell.self, forCellWithReuseIdentifier: "cell") + segmentedView.collectionView.register(JXSegmentedTitleImageCell.self, forCellWithReuseIdentifier: "imageCell") + segmentedView.collectionView.register(JXSegmentedTitleCell.self, forCellWithReuseIdentifier: "textCell") } open override func segmentedView(_ segmentedView: JXSegmentedView, cellForItemAt index: Int) -> JXSegmentedBaseCell { - let cell = segmentedView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) + let cellIdentifier: String + if hasImage(for: index) { + cellIdentifier = "imageCell" + } else { + cellIdentifier = "textCell" + } + let cell = segmentedView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, at: index) return cell } @@ -132,4 +141,8 @@ open class JXSegmentedTitleImageDataSource: JXSegmentedTitleDataSource { myCurrentSelectedItemModel.imageCurrentZoomScale = myCurrentSelectedItemModel.imageNormalZoomScale myWillSelectedItemModel.imageCurrentZoomScale = myWillSelectedItemModel.imageSelectedZoomScale } + + private func hasImage(for index: Int) -> Bool { + !(normalImageInfos?[index].isEmpty ?? true) + } } From e6f6e0922712e98b51003219ceb0131ede97529b Mon Sep 17 00:00:00 2001 From: Ivan <6350992+bivant@users.noreply.github.com> Date: Wed, 24 Sep 2025 13:38:08 +0300 Subject: [PATCH 2/2] Add option to omit image for a TitleImage segmented control item (by empty string in normalImageInfos) --- .../project.pbxproj | 4 + .../Base.lproj/Main.storyboard | 357 +++++++++--------- .../SpecialCustomizeViewController.swift | 4 + ...mentedControlOptionalImageController.swift | 116 ++++++ 4 files changed, 313 insertions(+), 168 deletions(-) create mode 100644 Example/JXSegmentedViewExample/Special/SegmentedControl/SegmentedControlOptionalImageController.swift diff --git a/Example/JXSegmentedViewExample.xcodeproj/project.pbxproj b/Example/JXSegmentedViewExample.xcodeproj/project.pbxproj index 43884d4..eb22637 100644 --- a/Example/JXSegmentedViewExample.xcodeproj/project.pbxproj +++ b/Example/JXSegmentedViewExample.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ 197927B326203F2800BDA8AE /* JXPagingListContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 197927AE26203F2800BDA8AE /* JXPagingListContainerView.swift */; }; 19F1D2F92339B0D100EEFB77 /* JXSegmentedView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1908F030226F14E000E03FD5 /* JXSegmentedView.framework */; }; 19F1D2FA2339B0D100EEFB77 /* JXSegmentedView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1908F030226F14E000E03FD5 /* JXSegmentedView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 21141B512E83D9740086998F /* SegmentedControlOptionalImageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21141B502E83D9690086998F /* SegmentedControlOptionalImageController.swift */; }; 96E5C2242E0E79AF00B24CE7 /* VerticalListWithCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E5C2232E0E79AF00B24CE7 /* VerticalListWithCollectionViewController.swift */; }; 96E5C2262E0E7BF200B24CE7 /* VerticalListCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E5C2252E0E7BF200B24CE7 /* VerticalListCollectionView.swift */; }; 96E5C2292E0E7C2100B24CE7 /* VerticalListSectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E5C2282E0E7C2100B24CE7 /* VerticalListSectionModel.swift */; }; @@ -133,6 +134,7 @@ 197927AC26203F2800BDA8AE /* JXPagingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JXPagingView.swift; sourceTree = ""; }; 197927AD26203F2800BDA8AE /* JXPagingListRefreshView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JXPagingListRefreshView.swift; sourceTree = ""; }; 197927AE26203F2800BDA8AE /* JXPagingListContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JXPagingListContainerView.swift; sourceTree = ""; }; + 21141B502E83D9690086998F /* SegmentedControlOptionalImageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedControlOptionalImageController.swift; sourceTree = ""; }; 96E5C2232E0E79AF00B24CE7 /* VerticalListWithCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticalListWithCollectionViewController.swift; sourceTree = ""; }; 96E5C2252E0E7BF200B24CE7 /* VerticalListCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticalListCollectionView.swift; sourceTree = ""; }; 96E5C2282E0E7C2100B24CE7 /* VerticalListSectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerticalListSectionModel.swift; sourceTree = ""; }; @@ -262,6 +264,7 @@ children = ( 1908EE6F226F05BA00E03FD5 /* NaviSegmentedControlViewController.swift */, 1908EE70226F05BA00E03FD5 /* SegmentedControlViewController.swift */, + 21141B502E83D9690086998F /* SegmentedControlOptionalImageController.swift */, ); path = SegmentedControl; sourceTree = ""; @@ -483,6 +486,7 @@ A8168092249CCB9900837DEC /* PagingListBaseCell.swift in Sources */, 1908EEBD226F05BA00E03FD5 /* LoadDataViewController.swift in Sources */, 197927B226203F2800BDA8AE /* JXPagingListRefreshView.swift in Sources */, + 21141B512E83D9740086998F /* SegmentedControlOptionalImageController.swift in Sources */, 1908EECA226F05BA00E03FD5 /* TestListBaseView.swift in Sources */, 1908EEC7226F05BA00E03FD5 /* CellCustomizeViewController.swift in Sources */, 96E5C2312E0E7E0F00B24CE7 /* VerticalSectionHeaderView.swift in Sources */, diff --git a/Example/JXSegmentedViewExample/Base.lproj/Main.storyboard b/Example/JXSegmentedViewExample/Base.lproj/Main.storyboard index 0379858..86c7600 100644 --- a/Example/JXSegmentedViewExample/Base.lproj/Main.storyboard +++ b/Example/JXSegmentedViewExample/Base.lproj/Main.storyboard @@ -19,14 +19,14 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - +