- iOS 10.0+
From CocoaPods
pod 'KFSegmentedView'
- Drag the
KFSegmentedView
folder to your project
- import
KFSegmentedView
in your workspace
import KFSegmentedView
- you need to create array of
KFSegmentedObject
let objs = [
KFSegmentObject(model:TestClass(), index: 0, title: "first", settings: setting),
KFSegmentObject(index: 1, title: "second", settings: setting),
KFSegmentObject(index: 2, title: "third", settings: setting),
KFSegmentObject(index: 3, title: "fourth", settings: setting)
]
- create an instance of
KFSegmentedViewController
in your workspace
let segmentedController = KFSegmentedController(delegate: self, items: objs)
- then you can add controller view as a child to main controller
add(child: segment, subview: backView) //this is an extension for UIViewController
- you need to add and conform to
KFSegmentedControllerDelegate
in main controller
extension ViewController : KFSegmentedControllerDelegate {
func segmentedSelectedItem(at index: Int, obj: KFSegmentObject) {
}
}
- to customize segmented view you have to set some properties
let setting = KFSetting(font: UIFont.systemFont(ofSize: 14), //optional
selectedTextColor: .black,
unselectedTextColor: .white,
selectedBackgroundColor: .white,
unselectedBackgroundColor: .clear,
selectedBorderColor: .black,
unselectedBorderColor: .clear,
borderWidth: 1, //optional
cornerRadius: 15) //optional
- note that you have to pass this setting to
KFSegmentObject
segment.semantic = .rtl //to changing segment view direction just set .rtl or .ltr
segment.cornerRadius = 15
segment.backgroundColor = .lightGray
segment.segmentSelectedIndex = 3 //defualt selected segment is 0
KFSegmentedView is released under an MIT license. See License.md for more information.