Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 "文字渐变":
//配置数据源
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion Sources/Title/JXSegmentedTitleCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
}

Expand Down
9 changes: 9 additions & 0 deletions Sources/Title/JXSegmentedTitleDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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值相同。
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/Title/JXSegmentedTitleItemModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down