Latest 0.1
Homepage https://github.com/yemeksepeti/YSSegmentedControl
License MIT
Platforms ios 8.0, requires ARC
Authors

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 = ...

Latest podspec

{
    "name": "YSSegmentedControl",
    "version": "0.1",
    "summary": "Android style segmented control written in swift. Fully customisable.",
    "description": "YSSegmentedControln==================nnAndroid style segmented control written in swift.nFully customisable.nnDemon----nn![alt tag](https://raw.githubusercontent.com/yemeksepeti/YSSegmentedControl/master/demo.gif)nnInstalln-------nn##### ManualnnCopy & paste `YSSegmentedControl.swift` in your projectnn##### Cocoapodsnn``` rubynuse_frameworks!npod 'YSSegmentedControl'n```nnUsagen-----nnCreate `YSSegmentedControl` with frame and titles.nYou can either use delegation or callback initilizationnn##### With callbacknn``` swiftnlet segmented = YSSegmentedControl(nframe: CGRect(nx: 0,ny: 64,nwidth: view.frame.size.width,nheight: 44),ntitles: [n"First",n"Second",n"Third"n],naction: {ncontrol, index innprintln ("segmented did pressed (index)")n})nn```nn##### With delegationnn``` swiftnlet segmented = YSSegmentedControl(nframe: CGRect(nx: 0,ny: 64,nwidth: view.frame.size.width,nheight: 44),ntitles: [n"First",n"Second",n"Third"n])n```nnSetup the delegate and you are ready to go !nn``` swiftnsegmented.delegate = selfn```nn### YSSegmentedControlDelegatenn``` [email protected] protocol YSSegmentedControlDelegate {noptional func segmentedControlWillPressItemAtIndex (segmentedControl: YSSegmentedControl, index: Int)noptional func segmentedControlDidPressedItemAtIndex (segmentedControl: YSSegmentedControl, index: Int)n}nn```nn### YSSegmentedControlAppearancenn``` swiftnstruct YSSegmentedControlAppearance {nnvar backgroundColor: UIColornvar selectedBackgroundColor: UIColornnvar textColor: UIColornvar font: UIFontnnvar selectedTextColor: UIColornvar selectedFont: UIFontnnvar bottomLineColor: UIColornvar selectorColor: UIColornnvar bottomLineHeight: CGFloatnvar selectorHeight: CGFloatn}n```nnThe default appearance isnn``` swiftnappearance = YSSegmentedControlAppearance(nnbackgroundColor: UIColor.clearColor(),nselectedBackgroundColor: UIColor.clearColor(),nntextColor: UIColor.grayColor(),nfont: UIFont.systemFontOfSize(15),nnselectedTextColor: UIColor.blackColor(),nselectedFont: UIFont.systemFontOfSize(15),nnbottomLineColor: UIColor.blackColor(),nselectorColor: UIColor.blackColor(),nnbottomLineHeight: 0.5,nselectorHeight: 2)n```nnYou can change appearance bynn``` swiftnsegmented.appearance = YSSegmentedAppearance (...)nn// ornnsegmented.appearance.titleColor = ...n```",
    "homepage": "https://github.com/yemeksepeti/YSSegmentedControl",
    "license": "MIT",
    "authors": {
        "cemolcay": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/yemeksepeti/YSSegmentedControl.git",
        "tag": "v0.1"
    },
    "source_files": "YSSegmentedControl/YSSegmentedControl/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This