BetterSegmentedControl is an easy to use, customizable replacement for UISegmentedControl and UISwitch written in Swift.
- Can be used as a segmented control or switch
- Plethora of customizable options from colors to insets and radii
- Designable straight in Interface Builder
- Customizable behavior
- Error handling
- iOS 8.0+
- Xcode 7.3+
BetterSegmentedControl is available through CocoaPods. To install it, simply add the following line to your Podfile:
Swift 4.0
pod 'BetterSegmentedControl', '~> 0.9'
Swift 3.0
pod 'BetterSegmentedControl', '0.8'
Swift 2.x
pod 'BetterSegmentedControl', '0.4'
If you prefer using Carthage, simply add BetterSegmentedControl to your Cartfile
:
Swift 4.0
github "gmarm/BetterSegmentedControl" ~> 0.9
Swift 3.0
github "gmarm/BetterSegmentedControl" 0.8
Swift 2.x
github "gmarm/BetterSegmentedControl" 0.4
If you prefer not to use CocoaPods or Carthage, you can integrate BetterSegmentedControl into your project manually.
let control = BetterSegmentedControl(
frame: CGRect(x: 0.0, y: 100.0, width: view.bounds.width, height: 44.0),
titles: ["One", "Two", "Three"],
index: 1,
options: [.backgroundColor(UIColor(red:0.11, green:0.12, blue:0.13, alpha:1.00)),
.titleColor(.white),
.indicatorViewBackgroundColor(UIColor(red:0.55, green:0.26, blue:0.86, alpha:1.00)),
.selectedTitleColor(.black),
.titleFont(UIFont(name: "HelveticaNeue", size: 14.0)!),
.selectedTitleFont(UIFont(name: "HelveticaNeue-Medium", size: 14.0)!)]
)
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.
- Get rid of unnecessary error handling.
- Add snapshot tests.
- Allow the control to have no selected index.
- Allow UIViews that implement a protocol to be used as options.
-
Try to take over the world!Uh, what?
Feel free to Fork, submit Pull Requests or send me your feedback and suggestions! Please make sure that tests are passing before submitting a new Pull Request.
George Marmaridis
- https://github.com/gmarm
- https://twitter.com/gmarmas
- https://www.linkedin.com/in/gmarm
- [email protected]
BetterSegmentedControl is available under the MIT license. See the LICENSE file for more info.
I'd greatly appreciate it if you drop me a line if you decide using it in one of your apps.