GithubHelp home page GithubHelp logo

smdulgeroglu / yssegmentedcontrol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yemeksepeti/yssegmentedcontrol

0.0 2.0 0.0 100 KB

Android style segmented control written in swift. Fully customisable.

License: MIT License

Ruby 44.16% Swift 55.84%

yssegmentedcontrol's Introduction

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

yssegmentedcontrol's People

Contributors

cemolcay avatar jeffaburt avatar jrmsklar avatar tusharsoni avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.