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..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)) @@ -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..8c69ff9 100644 --- a/Sources/Title/JXSegmentedTitleDataSource.swift +++ b/Sources/Title/JXSegmentedTitleDataSource.swift @@ -25,6 +25,12 @@ 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普通状态时的背景色 + open var bgNormalColor:UIColor = UIColor.clear /// title的颜色是否渐变过渡 open var isTitleColorGradientEnabled: Bool = false /// title是否缩放。使用该效果时,务必保证titleNormalFont和titleSelectedFont值相同。 @@ -54,6 +60,9 @@ 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 af67f94..a8af728 100644 --- a/Sources/Title/JXSegmentedTitleItemModel.swift +++ b/Sources/Title/JXSegmentedTitleItemModel.swift @@ -14,6 +14,9 @@ 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 bgCornerRadius: CGFloat = 0 open var titleNormalFont: UIFont = UIFont.systemFont(ofSize: 15) open var titleSelectedFont: UIFont = UIFont.systemFont(ofSize: 15) open var isTitleZoomEnabled: Bool = false