YSSegmentedControl

Android style segmented control written in swift. Fully customisable.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

123

Maintenance

Last Commit

4yrs ago

Contributors

6

Package

Dependencies

0

License

MIT

Categories

Readme

YSSegmentedControl

Android style segmented control written in swift.
Fully customisable.

Demo

alt tag

Install

Manual

Copy & paste YSSegmentedControl.swift in your project

CocoaPods
use_frameworks!
pod 'YSSegmentedControl'

Usage

Create YSSegmentedControl with frame and titles.
You can either use delegation or callback initilization

With callback
    let segmented = YSSegmentedControl(
        frame: CGRect(
            x: 0,
            y: 64,
            width: view.frame.size.width,
            height: 44),
        titles: [
            "First",
            "Second",
            "Third"
        ],
        action: {
            control, index in
            println ("segmented did pressed \(index)")
        })

With delegation
    let segmented = YSSegmentedControl(
        frame: CGRect(
            x: 0,
            y: 64,
            width: view.frame.size.width,
            height: 44),
        titles: [
            "First",
            "Second",
            "Third"
        ])

Setup the delegate and you are ready to go !

    segmented.delegate = self

YSSegmentedControlDelegate

@objc protocol YSSegmentedControlDelegate {
    optional func segmentedControlWillPressItemAtIndex (segmentedControl: YSSegmentedControl, index: Int)
    optional func segmentedControlDidPressedItemAtIndex (segmentedControl: YSSegmentedControl, index: Int)
}

YSSegmentedControlAppearance

    struct YSSegmentedControlAppearance {
        
        var backgroundColor: UIColor
        var selectedBackgroundColor: UIColor
        
        var textColor: UIColor
        var font: UIFont
        
        var selectedTextColor: UIColor
        var selectedFont: UIFont
        
        var bottomLineColor: UIColor
        var selectorColor: UIColor
        
        var bottomLineHeight: CGFloat
        var selectorHeight: CGFloat
    }

The default appearance is

   appearance = YSSegmentedControlAppearance(
       
       backgroundColor: UIColor.clearColor(),
       selectedBackgroundColor: UIColor.clearColor(),
       
       textColor: UIColor.grayColor(),
       font: UIFont.systemFontOfSize(15),
       
       selectedTextColor: UIColor.blackColor(),
       selectedFont: UIFont.systemFontOfSize(15),
       
       bottomLineColor: UIColor.blackColor(),
       selectorColor: UIColor.blackColor(),
       
       bottomLineHeight: 0.5,
       selectorHeight: 2)

You can change appearance by

    segmented.appearance = YSSegmentedAppearance (...)

    // or

    segmented.appearance.titleColor = ...

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100