If you're bored with standard segmented control, this framework is for you! CustomizableSegmentedControl
is a customizable segmented control written in SwiftUI 2.0.
- Supports any views
- Works with blend modes
- Works with right-to-left languages
- Easy to use
- iOS 14.0+
- Swift 5+
Add https://github.com/Inxel/CustomizableSegmentedControl
using Package Dependecies.
$ gem install cocoapods
To integrate CustomizableSegmentedControl
into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '14.0'
use_frameworks!
target '<Your Target Name>' do
pod 'CustomizableSegmentedControl'
end
Then, run the following command:
$ pod install
Just copy from CustomizableSegmentedControl.swift
file and paste it to your project.
Just setup CustomizableSegmentedControl
view with parameters:
CustomizableSegmentedControl(
selection: $selection,
options: [.one, .two, .three],
insets: .init(top: 4, leading: 4, bottom: 4, trailing: 4),
interSegmentSpacing: 2,
contentStyle: .withBlendMode(),
animation: .default,
selectionView: {
Color.white
.clipShape(RoundedRectangle(cornerRadius: 10))
},
segmentContent: { option, isPressed in
HStack(spacing: 4) {
Text(option.title)
.font(.system(size: 16, weight: .semibold, design: .rounded))
option.imageName.map(Image.init(systemName:))
}
.foregroundColor(.white.opacity(isPressed ? 0.7 : 1))
.lineLimit(1)
.padding(.vertical, 10)
.padding(.horizontal, 12)
.frame(maxWidth: .infinity)
}
)
.background(Color.blue)
.clipShape(RoundedRectangle(cornerRadius: 14))
Includes a small demo project showing how to use and customize it. Just clone the repo and build the Example project.
Every segment of control supports voiceover. By default, there is a text like "Selected, first option, one of three, button".
You can change accessibility value (in example it's "one of three") with CustomizableSegmentedControl extension segmentAccessibilityValue
which contains completion with index of current segment and total number of options.
Feel free to submit Pull Requests or send me your feedback and suggestions!
Artyom Zagoskin
CustomizableSegmentedControl
is available under the MIT license. See the LICENSE file for more info.