WBSegmentControl 0.2.3

WBSegmentControl 0.2.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年4月
SwiftSwift 版本3.0
SPM支持 SPM

Wonder Bear 维护。



  • xiongxiong

WBSegmentControl

一个易于使用、可定制的标签控件,可用来显示标签。

WBSegmentControl

内容

功能

  • [√] 弹性样式 - 彩虹 | 遮盖 | 条纹 | 箭头 | 箭头条纹
  • [√] 支持操作代理
  • [√] 自定义标签

要求

  • iOS 8.0+ / Mac OS X 10.11+ / tvOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

安装

手动

如果您不希望使用上述任何依赖管理器,可以将 WBSegmentControl 手动集成到您的项目中。

示例

打开示例项目,构建并运行。

协议

WBSegmentControlDelegate

public protocol WBSegmentControlDelegate {
    func segmentControl(segmentControl: WBSegmentControl, selectIndex newIndex: Int, oldIndex: Int)
}

WBSegmentProtocol

public protocol WBSegmentContentProtocol {
    var type: WBSegmentType { get }
}

用法

实现 WBSegmentContentProtocol

class TextSegment: NSObject, WBSegmentContentProtocol {

    var text: String!

    var type: WBSegmentType {
        return WBSegmentType.Text(text)
    }

    init(text: String) {
        super.init()

        self.text = text
    }
}

IconSegment 和 TextSegment 已实现,您可以直接使用,无需实现 WBSegmentContentProtocol,或者您可以选择实现 WBSegmentContentProtocol 以使用您自己的标签类型。

初始化标签控件

let segmentControl = WBSegmentControl() // initialize
view.addSubview(segmentControl)
...
segmentControl.segments = [
    TextSegment(text: "News China"),
    TextSegment(text: "Breaking News"),
] // set segments
segmentControl.style = .Rainbow // set style
segmentControl.selectedIndex = 0 // set selected index

实现 WBSegmentControlDelegate

extension MyViewController: WBSegmentControlDelegate {
    func segmentControl(segmentControl: WBSegmentControl, selectIndex newIndex: Int, oldIndex: Int) {

    }
}

获取选定标签

let selectedIndex = segmentControl.selectedIndex
let selectedSegment: TextSegment? = segmentControl.selectedSegment as? TextSegment

属性

设置 - 通用

  • indicatorStyle: IndicatorStyle = rainbow | cover | strip | arrow | arrowStrip
  • nonScrollDistributionStyle: NonScrollDistributionStyle = center | left | right | average
  • enableSeparator: Bool
  • separatorColor: UIColor
  • separatorWidth: CGFloat
  • separatorEdgeInsets: UIEdgeInsets
  • enableSlideway: Bool
  • slidewayHeight: CGFloat
  • slidewayColor: UIColor
  • enableAnimation: Bool
  • animationDuration: NSTimeInterval
  • contentBackgroundColor: UIColor
  • segmentMinWidth: CGFloat
  • segmentEdgeInsets: UIEdgeInsets
  • segmentTextBold: Bool
  • segmentTextFontSize: CGFloat
  • segmentTextForegroundColor: UIColor
  • segmentTextForegroundColorSelected: UIColor

设置 - indicatorStyle == .Rainbow

  • rainbow_colors: [UIColor]
  • rainbow_height: CGFloat
  • rainbow_roundCornerRadius: CGFloat
  • rainbow_location: RainbowLocation = up | down
  • rainbow_outsideColor: UIColor

设置 - indicatorStyle == .Cover

  • cover_range: CoverRange = segment | content
  • cover_opacity: Float
  • cover_color: UIColor

设置 - indicatorStyle == .Strip

  • strip_range: StripRange = segment | content
  • strip_location: StripLocation = up | down
  • strip_color: UIColor
  • strip_height: CGFloat

设置 - indicatorStyle == .Rainbow

public var rainbow_colors: [UIColor] = []
public var rainbow_height: CGFloat = 3
public var rainbow_roundCornerRadius: CGFloat = 4
public var rainbow_location: RainbowLocation = .Down
public var rainbow_outsideColor: UIColor = UIColor.grayColor()

设置 - indicatorStyle == .Arrow

  • arrow_size: CGSize
  • arrow_location: ArrowLocation = up | down
  • arrow_color: UIColor

设置 - indicatorStyle == .ArrowStrip

  • arrowStrip_location: ArrowStripLocation = up | down
  • arrowStrip_color: UIColor
  • arrowStrip_arrowSize: CGSize
  • arrowStrip_stripHeight: CGFloat
  • arrowStrip_stripRange: ArrowStripRange = segment | content

作者

xiongxiong, [email protected]

许可

WBSegmentControl 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。