PuiSegmentedControl是一个可自定义的分割控制器。
特性
- 根据UISegmentedControl进行更多配置
- 使用NSAttributedString.Key等配置标题样式,如字体、颜色等。
- 配置边框、背景、分隔符等样式。
- 动画分割变化(不与不同的圆角半径一起使用)。
- 在滚动UIPageViewController时支持滚动(与上述相同问题)。
- 支持PuiPageViewSegmentedControl的自定义页面视图。
- Swift编写:)
安装
CocoaPods
通过CocoaPods安装PuiSegmentedControl是最简单的方法。
pod 'PuiSegmentedControl'
Carthage
要使用Carthage将PuiSegmentedControl整合到您的Xcode项目中,在您的Cartfile中指定它
github "kemalbakacak/PuiSegmentedControl" ~> 2.0.0
运行carthage update
来构建框架,并将构建的 PuiSegmentedControl.framework
拖拽到您的Xcode项目中。
使用说明
- 将视图添加到你的故事板中,并设置类 PuiSegmentedControl。
- 创建出口并导入 PuiSegmentedControl 到你的视图控制器中。
- 最后,在设置标题之前根据你的设计设置属性。
- 您可以在“示例”文件夹下查看截图演示。
您可以使用的变量
open var animatedTabTransitionDuration: TimeInterval = 1 // The value of the animation tab when isAnimatedTabTransition property is true
open var animatedTabTransitionRedrawDifferenceDuration: TimeInterval = 0 // The value of the redraw view difference from transition duration when isAnimatedTabTransition property is true
open var backgroundCornerRadius: CGFloat = 0 // The radius of the background.
open var backgroundCustomColor: UIColor = .clear // The color of the background.
open var borderCornerRadius: CGFloat = 0 // The radius of the control's border.
open var borderColor: UIColor = .clear // The color of the control's border.
open var borderWidth: CGFloat = 2 // The size of the width control's border.
open var unselectedViewBackgroundColor: UIColor = .white // The color of the background color.
open var unselectedViewMargins: UIEdgeInsets = .zero // The offset of the background from all around.
open var unselectedTextAttributes: [NSAttributedString.Key: Any]? // The attributes of the segment's title
open var selectedViewBackgroundColor: UIColor = .purple // The color of the selected view background color.
open var selectedViewCornerRadius: CGFloat = .zero // The corner radius of selected view.
open var selectedViewMargins: UIEdgeInsets = .zero // The offset of the selected view from all around.
open var selectedTextAttributes: [NSAttributedString.Key: Any] = [:] // The attributes of the selected segment's title
open var selectedIndex: Int = 0 // The index of the selected segment's.
open var seperatorColor: UIColor = .purple // The color of the seperator's.
open var seperatorCornerRadius: CGFloat = 2 // The radius of the seperator's.
open var seperatorWidth: CGFloat = 4 // The size of the width seperator's
open var seperatorMarginBottom: CGFloat = 0 // The offset of the seperator's from bottom.
open var seperatorMarginTop: CGFloat = 0 // The offset of the seperator's from top.
open var isAnimatedTabTransition: Bool = false // If the property is true, tab transition will be animated.
open var isSelectViewAllCornerRadius: Bool = false // If the property is true, selected segment's will be rounded.
open var isEqualWidth: Bool = true // If the property is true, segments divided equals. Otherwise, segment's divided according to text length.
open var isSeperatorActive: Bool = true // If the property is true, seperator will show.
open var items: [String] = [] // The titles of segments.
与页面视图一起使用
如果您想与 Page View 一起使用,则需要使用 PuiPageViewSegmentedControl
并设置页面。您可以在示例项目中找到 PageViewController
的示例。如果您想与页面视图和选项卡控件一起使用,则将选项卡控件的属性发送到页面视图配置方法。阈值表示选定的段值变化的比率,0.8 表示 80%。
self.pageView.configure(pages: self.pages,
selectedIndex: 1,
segmentedControl: self.segmentedControl,
nextViewSelectionThreshold: 0.8)
许可
PuiSegmentedControl 以 MIT 许可发布。查看 LICENSE 以获取详细信息。