Skip to content

An easy to use, customizable replacement for UISegmentedControl & UISwitch.

License

Notifications You must be signed in to change notification settings

mkjwa/BetterSegmentedControl

 
 

Repository files navigation

BetterSegmentedControl

Version Carthage compatible License Platform

BetterSegmentedControl is an easy to use, customizable replacement for UISegmentedControl and UISwitch written in Swift.

Demo

Features

  • Can be used as a segmented control or switch
  • Plethora of customizable options from colors to insets, radii, animations
  • Use text or icons as segments, or add your own custom segments
  • Designable straight in Interface Builder
  • Customizable behavior
  • Right-to-left languages support

Requirements

  • iOS 9.0+
  • Xcode 8+

Installation

Swift Package Manager

BetterSegmentedControl is available through Swift Package Manager. To install it, simply go to Xcode under File > Swift Packages > Add Package Dependency...

CocoaPods

BetterSegmentedControl is available through CocoaPods. To install it, simply add the following line to your Podfile:

# Swift 5.1
pod 'BetterSegmentedControl', '~> 1.3'

# Swift 4
pod 'BetterSegmentedControl', '1.0'

# Swift 3 / Objective-C
pod 'BetterSegmentedControl', '0.8'

Carthage

If you prefer using Carthage, simply add BetterSegmentedControl to your Cartfile:

# Swift 5.1
github "gmarm/BetterSegmentedControl" ~> 1.3

# Swift 4
github "gmarm/BetterSegmentedControl" 1.0

# Swift 3 / Objective-C
github "gmarm/BetterSegmentedControl" 0.8

Manually

If you prefer not to use CocoaPods or Carthage, you can integrate BetterSegmentedControl into your project manually.

Usage

let control = BetterSegmentedControl(
    frame: CGRect(x: 0, y: 0, width: 300, height: 44),
    segments: LabelSegment.segments(withTitles: ["One", "Two", "Three"],
    normalFont: UIFont(name: "HelveticaNeue-Light", size: 14.0)!,
    normalTextColor: .lightGray,
    selectedFont: UIFont(name: "HelveticaNeue-Bold", size: 14.0)!,
    selectedTextColor: .white),
    index: 1,
    options: [.backgroundColor(.darkGray),
              .indicatorViewBackgroundColor(.blue)])
control.addTarget(self, action: #selector(ViewController.controlValueChanged(_:)), for: .valueChanged)
view.addSubview(control)

You can find different ways of using it (such as by designing it in a Storyboard file) in the example project. To run the example project, clone the repo, and run pod install from the Example directory first.

Contribution

Feel free to submit Pull Requests or send me your feedback and suggestions!

Author

George Marmaridis

License

BetterSegmentedControl is available under the MIT license. See the LICENSE file for more info.

About

An easy to use, customizable replacement for UISegmentedControl & UISwitch.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 97.5%
  • Ruby 2.5%