TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Apr 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Wonder Bear.
An easy to use, customizable segment control, can be used to show tabs.
If you prefer not to use either of the aforementioned dependency managers, you can integrate WBSegmentControl into your project manually.
Open the example project, build and run.
public protocol WBSegmentControlDelegate {
func segmentControl(segmentControl: WBSegmentControl, selectIndex newIndex: Int, oldIndex: Int)
}
public protocol WBSegmentContentProtocol {
var type: WBSegmentType { get }
}
class TextSegment: NSObject, WBSegmentContentProtocol {
var text: String!
var type: WBSegmentType {
return WBSegmentType.Text(text)
}
init(text: String) {
super.init()
self.text = text
}
}
IconSegment & TextSegment are already implemented, you can use it straightforwardly without implementing WBSegmentContentProtocol, or you can choose to implement WBSegmentContentProtocol to use your own segment type.
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
extension MyViewController: WBSegmentControlDelegate {
func segmentControl(segmentControl: WBSegmentControl, selectIndex newIndex: Int, oldIndex: Int) {
}
}
let selectedIndex = segmentControl.selectedIndex
let selectedSegment: TextSegment? = segmentControl.selectedSegment as? TextSegment
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()
xiongxiong, [email protected]
WBSegmentControl is available under the MIT license. See the LICENSE file for more info.