From 4f98236e415f5fe8ce7471ec77616a56114a550b Mon Sep 17 00:00:00 2001 From: "actionsljx@foxmail.com" Date: Wed, 15 Jan 2025 14:59:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A=20=E6=96=B0=E5=A2=9Etitledatascores=E4=B8=8B=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=AD=A3=E5=B8=B8=E7=8A=B6=E6=80=81=E7=9A=84=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/CellCustomizeViewController.swift | 1 + .../SegmentedControl/SegmentedControlViewController.swift | 2 -- Sources/Title/JXSegmentedTitleCell.swift | 2 ++ Sources/Title/JXSegmentedTitleDataSource.swift | 6 ++++++ Sources/Title/JXSegmentedTitleItemModel.swift | 2 ++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Example/JXSegmentedViewExample/Common/CellCustomizeViewController.swift b/Example/JXSegmentedViewExample/Common/CellCustomizeViewController.swift index cf7a02d..d983866 100644 --- a/Example/JXSegmentedViewExample/Common/CellCustomizeViewController.swift +++ b/Example/JXSegmentedViewExample/Common/CellCustomizeViewController.swift @@ -40,6 +40,7 @@ class CellCustomizeViewController: UITableViewController { dataSource.isTitleColorGradientEnabled = true dataSource.titleSelectedColor = UIColor.red dataSource.titles = titles + dataSource.bgNormalColor = UIColor.green vc.segmentedDataSource = dataSource case "文字渐变": //配置数据源 diff --git a/Example/JXSegmentedViewExample/Special/SegmentedControl/SegmentedControlViewController.swift b/Example/JXSegmentedViewExample/Special/SegmentedControl/SegmentedControlViewController.swift index 5398092..3e782d0 100644 --- a/Example/JXSegmentedViewExample/Special/SegmentedControl/SegmentedControlViewController.swift +++ b/Example/JXSegmentedViewExample/Special/SegmentedControl/SegmentedControlViewController.swift @@ -21,8 +21,6 @@ class SegmentedControlViewController: ContentBaseViewController { titleDataSource.itemWidth = totalItemWidth/CGFloat(titles.count) titleDataSource.titles = titles titleDataSource.isTitleMaskEnabled = true - titleDataSource.titleNormalColor = UIColor.red - titleDataSource.titleSelectedColor = UIColor.white titleDataSource.itemSpacing = 0 segmentedDataSource = titleDataSource diff --git a/Sources/Title/JXSegmentedTitleCell.swift b/Sources/Title/JXSegmentedTitleCell.swift index 0beb2e5..03423c5 100644 --- a/Sources/Title/JXSegmentedTitleCell.swift +++ b/Sources/Title/JXSegmentedTitleCell.swift @@ -73,9 +73,11 @@ open class JXSegmentedTitleCell: JXSegmentedBaseCell { if myItemModel.isSelected { titleLabel.font = myItemModel.titleSelectedFont maskTitleLabel.font = myItemModel.titleSelectedFont + self.backgroundColor = myItemModel.bgSelectedColor }else { titleLabel.font = myItemModel.titleNormalFont maskTitleLabel.font = myItemModel.titleNormalFont + self.backgroundColor = myItemModel.bgNormalColor } } diff --git a/Sources/Title/JXSegmentedTitleDataSource.swift b/Sources/Title/JXSegmentedTitleDataSource.swift index f7eedc0..f53d68d 100644 --- a/Sources/Title/JXSegmentedTitleDataSource.swift +++ b/Sources/Title/JXSegmentedTitleDataSource.swift @@ -25,6 +25,10 @@ open class JXSegmentedTitleDataSource: JXSegmentedBaseDataSource { open var titleNormalFont: UIFont = UIFont.systemFont(ofSize: 15) /// title选中时的字体。如果不赋值,就默认与titleNormalFont一样 open var titleSelectedFont: UIFont? + /// cell选中的背景色 + open var bgSelectedColor:UIColor = UIColor.clear + //// cell普通状态时的背景色 + open var bgNormalColor:UIColor = UIColor.clear /// title的颜色是否渐变过渡 open var isTitleColorGradientEnabled: Bool = false /// title是否缩放。使用该效果时,务必保证titleNormalFont和titleSelectedFont值相同。 @@ -54,6 +58,8 @@ open class JXSegmentedTitleDataSource: JXSegmentedBaseDataSource { } myItemModel.title = titles[index] + myItemModel.bgNormalColor = self.bgNormalColor + myItemModel.bgSelectedColor = self.bgSelectedColor myItemModel.textWidth = widthForTitle(myItemModel.title ?? "", index) myItemModel.titleNumberOfLines = innerTitleNumberOfLines(at: index) myItemModel.isSelectedAnimable = isSelectedAnimable diff --git a/Sources/Title/JXSegmentedTitleItemModel.swift b/Sources/Title/JXSegmentedTitleItemModel.swift index af67f94..2cfc547 100644 --- a/Sources/Title/JXSegmentedTitleItemModel.swift +++ b/Sources/Title/JXSegmentedTitleItemModel.swift @@ -14,6 +14,8 @@ open class JXSegmentedTitleItemModel: JXSegmentedBaseItemModel { open var titleNormalColor: UIColor = .black open var titleCurrentColor: UIColor = .black open var titleSelectedColor: UIColor = .red + open var bgSelectedColor: UIColor = .clear + open var bgNormalColor: UIColor = .clear open var titleNormalFont: UIFont = UIFont.systemFont(ofSize: 15) open var titleSelectedFont: UIFont = UIFont.systemFont(ofSize: 15) open var isTitleZoomEnabled: Bool = false From 596c555c862f8ed9d4b53aed973845d7520a26f9 Mon Sep 17 00:00:00 2001 From: "actionsljx@foxmail.com" Date: Wed, 15 Jan 2025 15:17:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=9C=86=E8=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Title/JXSegmentedTitleCell.swift | 1 + Sources/Title/JXSegmentedTitleDataSource.swift | 3 +++ Sources/Title/JXSegmentedTitleItemModel.swift | 1 + 3 files changed, 5 insertions(+) diff --git a/Sources/Title/JXSegmentedTitleCell.swift b/Sources/Title/JXSegmentedTitleCell.swift index 03423c5..556b109 100644 --- a/Sources/Title/JXSegmentedTitleCell.swift +++ b/Sources/Title/JXSegmentedTitleCell.swift @@ -78,6 +78,7 @@ open class JXSegmentedTitleCell: JXSegmentedBaseCell { titleLabel.font = myItemModel.titleNormalFont maskTitleLabel.font = myItemModel.titleNormalFont self.backgroundColor = myItemModel.bgNormalColor + self.layer.cornerRadius = myItemModel.bgCornerRadius } } diff --git a/Sources/Title/JXSegmentedTitleDataSource.swift b/Sources/Title/JXSegmentedTitleDataSource.swift index f53d68d..8c69ff9 100644 --- a/Sources/Title/JXSegmentedTitleDataSource.swift +++ b/Sources/Title/JXSegmentedTitleDataSource.swift @@ -25,6 +25,8 @@ open class JXSegmentedTitleDataSource: JXSegmentedBaseDataSource { open var titleNormalFont: UIFont = UIFont.systemFont(ofSize: 15) /// title选中时的字体。如果不赋值,就默认与titleNormalFont一样 open var titleSelectedFont: UIFont? + /// cell背景圆角 + open var bgCornerRadius: CGFloat = 0 /// cell选中的背景色 open var bgSelectedColor:UIColor = UIColor.clear //// cell普通状态时的背景色 @@ -60,6 +62,7 @@ open class JXSegmentedTitleDataSource: JXSegmentedBaseDataSource { myItemModel.title = titles[index] myItemModel.bgNormalColor = self.bgNormalColor myItemModel.bgSelectedColor = self.bgSelectedColor + myItemModel.bgCornerRadius = self.bgCornerRadius myItemModel.textWidth = widthForTitle(myItemModel.title ?? "", index) myItemModel.titleNumberOfLines = innerTitleNumberOfLines(at: index) myItemModel.isSelectedAnimable = isSelectedAnimable diff --git a/Sources/Title/JXSegmentedTitleItemModel.swift b/Sources/Title/JXSegmentedTitleItemModel.swift index 2cfc547..a8af728 100644 --- a/Sources/Title/JXSegmentedTitleItemModel.swift +++ b/Sources/Title/JXSegmentedTitleItemModel.swift @@ -16,6 +16,7 @@ open class JXSegmentedTitleItemModel: JXSegmentedBaseItemModel { open var titleSelectedColor: UIColor = .red open var bgSelectedColor: UIColor = .clear open var bgNormalColor: UIColor = .clear + open var bgCornerRadius: CGFloat = 0 open var titleNormalFont: UIFont = UIFont.systemFont(ofSize: 15) open var titleSelectedFont: UIFont = UIFont.systemFont(ofSize: 15) open var isTitleZoomEnabled: Bool = false From 1c376eea69c985e950fcaea3069c27e2b86bb170 Mon Sep 17 00:00:00 2001 From: "actionsljx@foxmail.com" Date: Wed, 15 Jan 2025 15:27:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=9C=86=E8=A7=92bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Title/JXSegmentedTitleCell.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Title/JXSegmentedTitleCell.swift b/Sources/Title/JXSegmentedTitleCell.swift index 556b109..6c3b4a9 100644 --- a/Sources/Title/JXSegmentedTitleCell.swift +++ b/Sources/Title/JXSegmentedTitleCell.swift @@ -52,7 +52,7 @@ open class JXSegmentedTitleCell: JXSegmentedBaseCell { titleLabel.numberOfLines = myItemModel.titleNumberOfLines maskTitleLabel.numberOfLines = myItemModel.titleNumberOfLines - + self.layer.cornerRadius = myItemModel.bgCornerRadius if myItemModel.isTitleZoomEnabled { //先把font设置为缩放的最大值,再缩小到最小值,最后根据当前的titleCurrentZoomScale值,进行缩放更新。这样就能避免transform从小到大时字体模糊 let maxScaleFont = UIFont(descriptor: myItemModel.titleNormalFont.fontDescriptor, size: myItemModel.titleNormalFont.pointSize*CGFloat(myItemModel.titleSelectedZoomScale)) @@ -78,7 +78,6 @@ open class JXSegmentedTitleCell: JXSegmentedBaseCell { titleLabel.font = myItemModel.titleNormalFont maskTitleLabel.font = myItemModel.titleNormalFont self.backgroundColor = myItemModel.bgNormalColor - self.layer.cornerRadius = myItemModel.bgCornerRadius } }