TFSegment
- 包含一些简单动画效果的选择器视图三方库
- github地址: https://github.com/554994782/TFSegment
Contents
-
支持版本
- Swift 4.1
- ARC
- iOS>=8.0
- iPhone \ iPad screen anyway
-
如何使用TFSegment
- 使用CocoaPods:
pod 'TFSegment'
- 其他方式:
- 将
TFSegment
文件夹拖入工程当中 - 引用:
import TFSegment
- 将
- 使用CocoaPods:
-
结构图
-
文件
TFSegmentView.swift TFItemLabel.swift TFSegmentStyle.swift TFColorRGB.swift Timer+Block.swift
例子
-
例子01 :文字颜色直接变,下标无拉伸变化
lazy var segmentView: TFSegmentView = {
let sv = TFSegmentView(frame: CGRect.init(x: 0, y: 60, width: UIScreen.main.bounds.width, height: 60), titles: titleArray)
sv.delegate = self
sv.delegateScrollView = scrollView
sv.titleStyle = .default //The text color of item change without animate 文字颜色直接变
sv.indicatorStyle = .default //Subscript without tensile change 下标无拉伸变化
sv.selectFontScale = 1.0 //Text scaling ratio 文字缩放比例(0.0~1.0)
return sv
}()
 
-
例子02 :文字颜色渐变,下标随文本长度变化
lazy var segmentView: TFSegmentView = {
let sv = TFSegmentView(frame: CGRect.init(x: 0, y: segmentView1.frame.maxY+2, width: UIScreen.main.bounds.width, height: 60), titles: titleArray)
sv.delegate = self
sv.delegateScrollView = scrollView
sv.titleStyle = .gradual //Text color gradient 文字颜色渐变
sv.indicatorStyle = .followText //Subscript varies with text length 下标随文本长度变化
return sv
}()
-
例子03 :文字颜色进度填充,下标拉伸变化
lazy var segmentView: TFSegmentView = {
let sv = TFSegmentView(frame: CGRect.init(x: 0, y: segmentView2.frame.maxY+2, width: UIScreen.main.bounds.width, height: 60), titles: titleArray)
sv.delegate = self
sv.delegateScrollView = scrollView
sv.titleStyle = .fill //Text color progress fill 文字颜色进度填充
sv.indicatorStyle = .stretch //Subscript varies with stretch下标拉伸变化
return sv
}()
-
例子04 :文字颜色进度填充,下标随文本长度变化且拉伸变化
lazy var segmentView: TFSegmentView = {
let sv = TFSegmentView(frame: CGRect.init(x: 0, y: segmentView3.frame.maxY+2, width: UIScreen.main.bounds.width, height: 60), titles: titleArray)
sv.delegate = self
sv.delegateScrollView = scrollView
sv.titleStyle = .fill //Text color progress fill 文字颜色进度填充
sv.indicatorStyle = .followTextStretch // Subscript varies with text length and stretch下标随文本长度变化 且 拉伸变化
return sv
}()
- 例子05 :其他公开属性
/**Background color, default white / 背景颜色, 默认白色*/
public var backColor: UIColor = UIColor.white
/**Item maximum display, default 8 / Item最大显示数, 默认8*/
public var maxItemCount: NSInteger = 8
/**Item width, split without setting / Item宽度, 不设置则平分*/
public var tabItemWidth: CGFloat = 0.0
/**Text effect of item / Item的文字效果*/
public var titleStyle: TFTitleTransformStyle = .default
/**Selected font color / 选中字体颜色*/
public var selectedColor: UIColor = UIColor.red
/**UnSelected font color / 未选中字体颜色*/
public var unSelectedColor: UIColor = UIColor.black
/**Text font size, default 18 / 默认字体大小, 默认18*/
public var titleFont: UIFont = UIFont.systemFont(ofSize: 18)
/**UnSelected font reduction, default is 0.8(0~1) / 未选中字体缩小比例,默认是0.8(0~1)*/
public var selectFontScale: CGFloat = 0.8
/**Subscript effect / 下标效果*/
public var indicatorStyle: TFIndicatorWidthStyle = .default
/**Subscript height, default 2.0 / 下标高度,默认是2.0*/
public var indicatorHeight: CGFloat = 2.0
/**Subscript width, default is 30 / 下标宽度,默认是30*/
public var indicatorWidth: CGFloat = 30.0
/**Bottom Secant Color, default clear / 底部分割线颜色, 默认透明*/
public var separatorColor: UIColor = UIColor.clear
必须要做的
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
segmentView.scrollViewDidScroll(scrollView)
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
segmentView.scrollViewDidEndDecelerating(scrollView)
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
segmentView.scrollViewDidEndScrollingAnimation(scrollView)
}
}