SJSegmentedScrollView is a light weight generic controller written in Swift 2.3. Its a simple customizable controller were you can integrate any number of ViewControllers into a segmented controller with a header view controller.
- Horizontal scrolling for switching from segment to segment.
- Vertical scrolling for contents.
- Single header view for all segments.
- Title, segment selection color, header size, segment height etc can be customized accordingly.
To integrate SJSegmentedViewController into your Xcode project using CocoaPods, specify it in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod ’SJSegmentedScrollView’, ‘1.0.9'
endThen, run the following command:
$ pod install- Download SJSegmentedViewController.
- Drag and drop SJSegmentedViewController directory to your project
iOS 8.0+, Swift 2.3
Here is how you can use SJSegmentedViewController.
You can add any number of ViewControllers into SJSegmentedViewController. All you have to do is as follows.
if let storyboard = self.storyboard {
let headerViewController = storyboard
.instantiateViewControllerWithIdentifier("HeaderViewController")
let firstViewController = storyboard
.instantiateViewControllerWithIdentifier("FirstTableViewController")
firstViewController.title = "First"
let secondViewController = storyboard
.instantiateViewControllerWithIdentifier("SecondTableViewController")
secondViewController.title = "Second"
let thirdViewController = storyboard
.instantiateViewControllerWithIdentifier("ThirdTableViewController")
thirdViewController.title = "Third"
let segmentedViewController = SJSegmentedViewController(headerViewController: headerViewController,
segmentControllers: [firstViewController,
secondViewController,
thirdViewController])
self.presentViewController(segmentedViewController, animated: false, completion: nil)
}By default, SJSegmentedScrollView will observe the default view of viewcontroller for content changes and makes the scroll effect. If you want to change the default view, implement SJSegmentedViewControllerViewSource and pass your custom view.
func viewForSegmentControllerToObserveContentOffsetChange(controller: UIViewController,
index: Int) -> UIView {
return view
}You can also customize your controllers by using following properties in SJSegmentedViewController.
let segmentedViewController = SJSegmentedViewController()
//Set height for headerview.
segmentedViewController.headerViewHeight = 250.0
//Set height for segmentview.
segmentedViewController.segmentViewHeight = 60.0
//Set color for selected segment.
segmentedViewController.selectedSegmentViewColor = UIColor.redColor()
//Set color for segment title.
segmentedViewController.segmentTitleColor = UIColor.blackColor()
//Set background color for segmentview.
segmentedViewController.segmentBackgroundColor = UIColor.whiteColor()
//Set font for segmentview titles.
segmentedViewController.segmentTitleFont = UIFont.systemFontOfSize(14.0)
//Set height for selected segmentview.
segmentedViewController.selectedSegmentViewHeight = 5.0
//Set height for headerview to visible after scrolling
segmentedViewController. headerViewOffsetHeight = 10.0Subins Jose, subinsjose@gmail.com
SJSegmentedScrollView is available under the MIT license. See the LICENSE file for more info.
