Containers are a new way of organizing objects in iOS and macOS. They allow you to be more productive by grouping related items for easier access into one location, but can also lead to confusion when trying to glue together different app screens that require multiple containers. This tutorial will show how you can create your own container view controller that seamlessly displays the content from each possible child ViewController on an iPhone or iPad running Xcode 10 beta 8+.
“scrollablesegmentedcontrol” is a fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. It uses the UIScrollViewDelegate protocol and can be customized by adding subclasses or implementing its delegate methods.
This is a Swift-based control for iOS. DTPagerController is straightforward to set up and configure.
Controls that are segmented by default
Control divided to your liking
DTPagerController is a very simple program to use. Two view controllers must be shown inside a pager controller. You just need to write this many lines of code.
allow the public to see ViewController() = ViewController1 = ViewController1 = ViewController1 = ViewController1 = let pagerController = DTPagerController let controller2 = ViewController() (viewControllers: [viewController1, viewController2])
Refresh the page index
There are three distinct methods to programmatically change a chosen page index.
With animation pagerController, update the chosen page index. 1 for selectedPageIndex With animation pagerController, update the chosen page index. setSelectedPageIndex is a function that returns the index of the selected page (1, animated: true) / PagerController is not used to update the chosen page index. setSelectedPageIndex is a function that returns the index of the selected page (1, animated: false)
DTPagerController may also be customized if you wish to create your own user interface.
PagerController.preferredSegmentedControlHeight = 60; / Change the height of the segmented control pagerController.preferredSegmentedControlHeight = 60; Each segmented control pagerController’s usual font is changed. UIFont.customFont; font = UIFont.customFont; font = UIFont.custom (ofSize: 15) / Set the font for each divided control pagerController.selected UIFont.boldCustomFont; font = UIFont.boldCustomFont; font = UIFont.bol (ofSize: 15) / Change the color of each segmented control pagerController’s normal text. UIColor.black as textColor Change the color of the chosen text in each segmented control pagerController.selected UIColor.red = TextColor PagerController.perferredScrollIndicatorHeight = 3; / Change the height of the scroll indicator
Control divided to your liking
DTPagerController allows configurable segmented control as of version 2.0.0. As a result, instead of utilizing the default DTSegmentedControl, you may use your own segmented control or any of the available 3rd-party segmented control libraries. It’s as simple as conforming your own UIControl to the DTSegmentedControlProtocol. For instance, in the sample project, HMSegmentedControl is modified to adhere to the DTSegmentedControlProtocol by applying the extension:
public func setImage(_ image: UIImage?, forSegmentAt segment: Int) in extension HMSegmentedControl: DTSegmentedControlProtocol / There is no support for custom page controls. set public func forSegmentAt segment: Int, title(_ title: String?, forSegmentAt segment: Int) / There is no support for custom page controls. set public func attributes: [AnyHashable: Any]?, for state: UIControlState) TitleTextAttributes( attributes: [AnyHashable: Any]?, for state: UIControlState) If state is UIControlState.normal, titleTextAttributes = attributes; otherwise, if state is UIControlState.selected, selectedTitleTextAttributes = attributes
Then, using the custom segmented control, we build a new pager controller:
start (viewControllers controllers: [UIViewController]) if segmentedControl = HMSegmentedControl, then (sectionTitles: [“Page 1”, “Page 2”, “Page 3”]) super. viewControllers: controllers, pageSegmentedControl: segmentedControl!) init(viewControllers: controllers, pageSegmentedControl: segmentedControl!) }
It is recommended that while using custom segmented control, you override/look at the following methods to modify the behavior and appearance of each segment:
Setup a custom segmented control using the setUpSegmentedControl function (viewControllers: [UIViewController]) / Update a segment’s custom look using the updateAppearanceForSegmentedItem function (at index: Int) If a custom scroll indicator exists, update it using the updateScrollIndicator function (with offsetRatio: CGFloat, scrollView: UIScrollView) Set up a custom scroll indicator using the setUpScrollIndicator function () SetTitle(_ title: String?, forSegmentAt segment: Int) is used to manually change the segment title. SetImage(_ image: UIImage?, forSegmentAt segment: Int) to manually change the segment image.
Clone the repo and run pod install from the Example directory to start the example project.
Simply put, in your Podfile, add the following line:
Swift 5 has the following features:
‘DTPagerController’ is a pod.
For Swift 4.2, make the following changes:
> 2.0.4′ pod ‘DTPagerController’
Package management for Swift
From version 3.0.2 onwards, DTPagerController is available for SPM. Add the following to your Package’s dependencies. swift:
.package(from: “version”), url: “https://github.com/tungvoduc/DTPagerController”
[email protected] Tung Vo
DTPagerController is free to use and distribute under the MIT license. For further information, see the LICENSE file.
Requests and feedback
- Create a new problem If you discover a problem, have a suggestion, or just need assistance, please contact us.
- You may also reach out to me via email.
The “ios slide view up from bottom github” is a fully customizable container view controller that allows users to display a set of ViewControllers in a horizontal scroll view.
- uisegmentedcontrol multiple selection
- scrollable tab bar ios swift github