Customizable segmented control with style presets...
RESegmentedControl is customizable segmented control with style presets.
Main Features | |
---|---|
🎨 | Supports style presets |
🎫 | Supports texts and images |
🧮 | Supports vertical and horizontal content layout |
📥 | Able to download and cache images |
🎢 | Natural and smooth animation between segments selection |
🥌 | Layout-Driven UI |
🚀 | Written in Swift |
import RESegmentedControl
UIView
to Storyboard's ViewController. Change class and module to RESegmentedControl
and @IBOutlet to your ViewController:/// Segmented Control
@IBOutlet weak var segmentedControl: RESegmentedControl!
or create a RESegmentedControl
programmatically:
let segmentedControl = RESegmentedControl(frame: CGRect(x: 0, y: 0, width: 200, height: 44))
self.view.addSubview(segmentedControl)
// TODO: Add segmentedControl Auto-Layouts…
// Specify a list of string that will be shown
let titles = ["safari", "chrome", "firefox"]
// Map a list of string to the [SegmentModel]
var segmentItems: [SegmentModel] {
return titles.map({ SegmentModel(title: $0) })
}
// Create a preset to style the segmentedControl
let preset = BootstapPreset(backgroundColor: .white, selectedBackgroundColor: .black)
// segmentedControl configuration method
segmentedControl.configure(segmentItems: segmentItems, preset: preset)
To learn more, take a look at the demo project.
RESegmentedControl
initialize with a list of SegmentModel
. RESegmentedControl
could be shown in three ways, with text only, image only or with text and image.
SegmentModel
with title
variable:let segmentsItem: [SegmentModel] = [SegmentModel(title: “Title”)]
SegmentModel
with imageName
variable:let segmentsItem: [SegmentModel] = [SegmentModel(imageName: “imageNameInAseetCatalog”)]
initiate a SegmentModel
with imageUrl
variable to load image from remote server:
let imageUrl = “https://domain.com/image.png”
let segmentsItem: [SegmentModel] = [SegmentModel(imageUrl: imageUrl)]
SegmentModel
with title
and imageName
or imageUrl
variable:let segmentsItem: [SegmentModel] = [SegmentModel(title: “Title”, imageName: “imageNameInAseetCatalog”)]
// Image remote location url
let imageUrl = “https://domain.com/image.png”
let segmentsItem: [SegmentModel] = [SegmentModel(title: “Title”, imageUrl: imageUrl)]
For more information, see
BasicExampleViewController
in the demo project.
func addItem(_ item: SegmentModel, atIndex index: Int? = nil)
func removeItem(atIndex index: Int? = nil)
var segmentItemsCount: Int
var selectedSegmentIndex: Int
func deselect()
func replaceItem(_ item: SegmentModel, atIndex index: Int)
For more information, see
ActionViewController
in the demo project.
RESegmentedControl
supports a wide range of customization appearance. It is also possible to apply ready-made presets of styles or create your own preset.
Currently 4 presets are available:
struct iOS7Preset: SegmentedControlPresettable
struct iOS13Preset: SegmentedControlPresettable
struct MaterialPreset: SegmentedControlPresettable
struct BootstapPreset: SegmentedControlPresettable
For more information, see
PresetsViewController
in the demo project.
To learn more about how to create a preset, follow the Advanced Style Guide.
To learn more see a full API Reference, and check out the demo project included in the repository. When you are ready to install, follow the Installation Guide.
App version | Swift | Xcode | Platforms |
---|---|---|---|
current version | Swift 5.0 | Xcode 12 | iOS 9.0 |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Sherzod Khashimov
See changelog here
RESegmentedControl is available under the MIT license. See the LICENSE file for more info.