Top Related Projects
A highly customizable drop-in replacement for UISegmentedControl.
Android PagerTabStrip for iOS.
A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram)
:octocat: AdaptiveController is a 'Progressive Reduction' Swift UI module for adding custom states to Native or Custom iOS UI elements. Swift UI component by @Ramotion
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.
Quick Overview
Segmentio is a Swift library that provides a simple and customizable way to implement a segmented control UI element in iOS applications. It offers a range of features and customization options to help developers create visually appealing and interactive segmented controls.
Pros
- Customizable Appearance: Segmentio allows developers to easily customize the appearance of the segmented control, including the font, color, and size of the segment titles.
- Smooth Animations: The library provides smooth animations when switching between segments, enhancing the overall user experience.
- Flexible Layout: Segmentio can be used in a variety of layouts, including horizontal, vertical, and even circular configurations.
- Lightweight and Efficient: The library is lightweight and efficient, with a small footprint and minimal impact on app performance.
Cons
- Limited Functionality: While Segmentio provides a good set of features, it may not offer the full range of functionality that some developers might require for more complex segmented control implementations.
- Dependency on Swift: Segmentio is written in Swift, which means it can only be used in Swift-based projects and may not be compatible with Objective-C codebases.
- Potential Learning Curve: Developers who are new to Segmentio or Swift may need to invest some time in learning how to use the library effectively.
- Lack of Active Maintenance: The Segmentio repository on GitHub has not been actively maintained in recent years, which may raise concerns about long-term support and compatibility with newer iOS versions.
Code Examples
Here are a few examples of how to use Segmentio in your Swift project:
Creating a Segmented Control
let segmentedControl = SegmentioView(frame: CGRect(x: 20, y: 50, width: view.frame.width - 40, height: 50))
segmentedControl.setup(with: ["Option 1", "Option 2", "Option 3"], style: .onlyLabel)
view.addSubview(segmentedControl)
This code creates a new SegmentioView
instance and sets up the segmented control with three options.
Customizing the Appearance
segmentedControl.backgroundColor = .white
segmentedControl.selectedSegmentIndex = 1
segmentedControl.font = UIFont.systemFont(ofSize: 16, weight: .medium)
segmentedControl.textColor = .gray
segmentedControl.selectedTextColor = .black
This code customizes the appearance of the segmented control, including the background color, selected segment index, font, and text colors.
Handling Segment Selection
segmentedControl.didTapOnSegment = { (index, title) in
print("Tapped on segment \(index) with title \(title)")
}
This code sets up a closure that will be called whenever a segment is tapped, providing the index and title of the selected segment.
Getting Started
To get started with Segmentio, follow these steps:
-
Add the Segmentio library to your project. You can do this by using a package manager like CocoaPods or Carthage, or by manually adding the source files to your project.
-
Import the Segmentio library in your Swift file:
import Segmentio
-
Create a new
SegmentioView
instance and set up the segments:let segmentedControl = SegmentioView(frame: CGRect(x: 20, y: 50, width: view.frame.width - 40, height: 50)) segmentedControl.setup(with: ["Option 1", "Option 2", "Option 3"], style: .onlyLabel) view.addSubview(segmentedControl)
-
Customize the appearance of the segmented control as needed:
segmentedControl.backgroundColor = .white segmentedControl.selectedSegmentIndex = 1 segmentedControl.font = UIFont.systemFont(ofSize: 16, weight: .medium) segmentedControl.textColor = .gray segmentedControl.selectedTextColor = .black
Competitor Comparisons
A highly customizable drop-in replacement for UISegmentedControl.
Pros of HMSegmentedControl
- Customizable appearance: HMSegmentedControl allows for a high degree of customization, including the ability to change the font, color, and size of the segment titles.
- Smooth animation: The control provides smooth animation when switching between segments, which can enhance the user experience.
- Flexible layout: HMSegmentedControl can be easily integrated into different layouts and can be used in both storyboards and programmatically.
Cons of HMSegmentedControl
- Limited functionality: Compared to Segmentio, HMSegmentedControl has a more limited set of features, such as the lack of support for images or icons in the segments.
- Older codebase: The HMSegmentedControl project has not been actively maintained since 2015, which may be a concern for developers looking for a more up-to-date solution.
Code Comparison
Segmentio:
let segmentedControl = SegmentioView(frame: CGRect(x: 0, y: 0, width: 300, height: 50))
segmentedControl.options = SegmentioOptions(
backgroundColor: .white,
titleLabelTextColor: .gray,
titleLabelFont: UIFont.systemFont(ofSize: 14),
imagePosition: .left,
segmentPosition: .dynamic,
horizontalSeparatorColor: .lightGray,
verticalSeparatorColor: .lightGray
)
segmentedControl.segments = [
SegmentioItem(title: "First", image: UIImage(named: "first")),
SegmentioItem(title: "Second", image: UIImage(named: "second")),
SegmentioItem(title: "Third", image: UIImage(named: "third"))
]
HMSegmentedControl:
let segmentedControl = HMSegmentedControl(sectionTitles: ["First", "Second", "Third"])
segmentedControl.frame = CGRect(x: 0, y: 0, width: 300, height: 50)
segmentedControl.backgroundColor = .white
segmentedControl.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.gray]
segmentedControl.selectedTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
segmentedControl.selectionIndicatorColor = .lightGray
Android PagerTabStrip for iOS.
Pros of XLPagerTabStrip
- Supports a wide range of customization options, including custom cell views and indicators.
- Provides a smooth and responsive user experience with animations and gestures.
- Integrates well with other popular iOS frameworks, such as UICollectionView and UITableView.
Cons of XLPagerTabStrip
- May have a steeper learning curve compared to Segmentio, especially for developers new to the framework.
- Requires more boilerplate code to set up and configure the pager tab strip.
- Potentially less performant than Segmentio for simple use cases due to the additional features and complexity.
Code Comparison
Segmentio:
let segmentedControl = SegmentedControl(items: ["First", "Second", "Third"])
segmentedControl.addTarget(self, action: #selector(segmentedControlValueChanged(_:)), for: .valueChanged)
view.addSubview(segmentedControl)
XLPagerTabStrip:
let pagerTabStripViewController = ButtonBarPagerTabStripViewController(nibName: "ButtonBarPagerTabStripViewController", bundle: nil)
pagerTabStripViewController.delegate = self
pagerTabStripViewController.dataSource = self
view.addSubview(pagerTabStripViewController.view)
A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram)
Pros of PageMenu/PageMenu
- Customizable Appearance: PageMenu provides a high degree of customization, allowing developers to adjust the appearance of the menu to match their app's design.
- Smooth Scrolling: The library offers smooth scrolling between menu items, providing a seamless user experience.
- Responsive Design: PageMenu is designed to work well on a variety of screen sizes, making it suitable for both iOS and iPad devices.
Cons of PageMenu/PageMenu
- Limited Functionality: Compared to Segmentio, PageMenu may have a more limited set of features and functionality, which could be a drawback for developers with more complex requirements.
- Potential Performance Issues: Some users have reported occasional performance issues, particularly with large numbers of menu items or complex content within the view controllers.
Code Comparison
PageMenu
let pages: [UIViewController] = [ViewController1(), ViewController2(), ViewController3()]
let pageMenu = CAPSPageMenu(viewControllers: pages, frame: CGRect(x: 0.0, y: 20.0, width: self.view.frame.width, height: self.view.frame.height - 20.0), options: [.scrollMenuBackgroundColor(UIColor.white), .viewBackgroundColor(UIColor.white), .menuItemFont(UIFont(name: "HelveticaNeue", size: 13.0)!), .menuHeight(34.0), .selectionIndicatorHeight(3.0), .bottomMenuHairlineColor(UIColor(red: 223/255, green: 223/255, blue: 223/255, alpha: 1.0)), .menuItemSeparatorColor(UIColor(red: 223/255, green: 223/255, blue: 223/255, alpha: 1.0))])
Segmentio
let segmentio = Segmentio(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44))
segmentio.dataSource = self
segmentio.delegate = self
segmentio.backgroundColor = .white
segmentio.selectedSegmentioIndex = 0
segmentio.segmentioStyle = .onlyLabel
segmentio.segmentioPosition = .top
segmentio.font = UIFont.systemFont(ofSize: 14)
segmentio.textColor = .gray
segmentio.selectedTextColor = .black
segmentio.indicatorColor = .black
:octocat: AdaptiveController is a 'Progressive Reduction' Swift UI module for adding custom states to Native or Custom iOS UI elements. Swift UI component by @Ramotion
Pros of Adaptive Tab Bar
- Supports both iOS and Android platforms, making it a versatile solution.
- Provides a smooth and responsive tab bar experience with adaptive behavior.
- Includes various customization options for the tab bar's appearance and behavior.
Cons of Adaptive Tab Bar
- May have a steeper learning curve compared to Segmentio, as it offers more advanced features.
- Potentially less lightweight and more resource-intensive than Segmentio, depending on the project's requirements.
- May have a smaller community and fewer resources available compared to the more established Segmentio.
Code Comparison
Segmentio:
let segmentedControl = SegmentedControl(items: ["One", "Two", "Three"])
segmentedControl.addTarget(self, action: #selector(segmentedControlValueChanged(_:)), for: .valueChanged)
view.addSubview(segmentedControl)
Adaptive Tab Bar:
let tabBar = AdaptiveTabBar(items: [
AdaptiveTabBarItem(title: "Home", image: UIImage(named: "home")),
AdaptiveTabBarItem(title: "Search", image: UIImage(named: "search")),
AdaptiveTabBarItem(title: "Profile", image: UIImage(named: "profile"))
])
view.addSubview(tabBar)
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.
Pros of FSPagerView
- FSPagerView provides a highly customizable and feature-rich pager view, allowing for a wide range of UI configurations and interactions.
- The library includes built-in support for various pager styles, such as infinite scrolling, page indicators, and automatic scrolling.
- FSPagerView has a well-documented API and a large community, making it easier to integrate and maintain within a project.
Cons of FSPagerView
- The library may have a steeper learning curve compared to Segmentio, as it offers a more comprehensive set of features and customization options.
- The performance of FSPagerView may be slightly lower than Segmentio, especially for large datasets or complex UI configurations.
Code Comparison
Segmentio:
let segmentedControl = SegmentedControl(items: ["Option 1", "Option 2", "Option 3"])
segmentedControl.addTarget(self, action: #selector(segmentedControlValueChanged(_:)), for: .valueChanged)
view.addSubview(segmentedControl)
FSPagerView:
let pagerView = FSPagerView(frame: view.bounds)
pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
pagerView.dataSource = self
pagerView.delegate = self
view.addSubview(pagerView)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Segmentio
Animated top/bottom segmented control written in Swift.
Check this project on dribbble.
Requirements
- Xcode 10
- iOS 8.x+
- Swift 5.0
Installation
CocoaPods
use_frameworks!
pod 'Segmentio'
CocoaPods v1.1.0 or later required
Carthage
github "Yalantis/Segmentio"
Usage
Import Segmentio
module
import Segmentio
Init
You can initialize a Segmentio
instance from code:
var segmentioView: Segmentio!
let segmentioViewRect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 125)
segmentioView = Segmentio(frame: segmentioViewRect)
view.addSubview(segmentioView)
or
add a UIView
instance in your .storyboard or .xib, set Segmentio
class and connect IBOutlet
:
@IBOutlet weak var segmentioView: Segmentio!
Setup Segmentio
segmentioView.setup(
content: [SegmentioItem],
style: SegmentioStyle,
options: SegmentioOptions?
)
To start with default options you can just pass nil
to the options
parameter.
segmentioView.setup(
content: [SegmentioItem],
style: SegmentioStyle,
options: nil
)
Configuring items
In order to set items you need to create an array of SegmentioItem
instances:
var content = [SegmentioItem]()
let tornadoItem = SegmentioItem(
title: "Tornado",
image: UIImage(named: "tornado")
)
content.append(tornadoItem)
Handling selection
You can specify selected item manually:
segmentioView.selectedSegmentioIndex = 0
Handling callback
segmentioView.valueDidChange = { segmentio, segmentIndex in
print("Selected item: ", segmentIndex)
}
Customization
Segmentio
can be customized by passing an instance of SegmentioOptions
struct:
SegmentioOptions(
backgroundColor: .white,
segmentPosition: SegmentioPosition,
scrollEnabled: true,
indicatorOptions: SegmentioIndicatorOptions,
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
imageContentMode: .center,
labelTextAlignment: .center,
segmentStates: SegmentioStates
)
Segment width rely on SegmentioPosition
enum. Width can be fixed according to maximum visible items or dynamic according to segment's content size:
enum SegmentioPosition {
case dynamic
case fixed(maxVisibleItems: Int)
}
Selection indicator can be customized by passing an instance of SegmentioIndicatorOptions
:
SegmentioIndicatorOptions(
type: .bottom,
ratio: 1,
height: 5,
color: .orange
)
Horizontal borders can be customized by passing an instance of SegmentioHorizontalSeparatorOptions
:
SegmentioHorizontalSeparatorOptions(
type: SegmentioHorizontalSeparatorType.topAndBottom, // Top, Bottom, TopAndBottom
height: 1,
color: .gray
)
Separators between segments can be customized by passing an instance of SegmentioVerticalSeparatorOptions
:
SegmentioVerticalSeparatorOptions(
ratio: 0.6, // from 0.1 to 1
color: .gray
)
In order to set SegmentioStates
you need to create a tuple of SegmentioState
instances:
SegmentioStates(
defaultState: SegmentioState(
backgroundColor: .clear,
titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: .black
),
selectedState: SegmentioState(
backgroundColor: .orange,
titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: .white
),
highlightedState: SegmentioState(
backgroundColor: UIColor.lightGray.withAlphaComponent(0.6),
titleFont: UIFont.boldSystemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: .black
)
)
Let us know!
Weâd be really happy if you sent us links to your projects where you use our component. Just send an email to github@yalantis.com And do let us know if you have any questions or suggestion regarding the animation.
P.S. Weâre going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned!
License
The MIT License (MIT)
Copyright © 2019 Yalantis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Top Related Projects
A highly customizable drop-in replacement for UISegmentedControl.
Android PagerTabStrip for iOS.
A paging menu controller built from other view controllers placed inside a scroll view (like Spotify, Windows Phone, Instagram)
:octocat: AdaptiveController is a 'Progressive Reduction' Swift UI module for adding custom states to Native or Custom iOS UI elements. Swift UI component by @Ramotion
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot