Skip to content

hoootan/KFSegmentedView

Repository files navigation

KFSegmentedView

Requirements

  • iOS 10.0+

Installation

pod 'KFSegmentedView'

From source

  • Drag the KFSegmentedView folder to your project

Getting Started

  1. import KFSegmentedView in your workspace
import KFSegmentedView
  1. 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)
        ]
  1. create an instance of KFSegmentedViewController in your workspace
let segmentedController = KFSegmentedController(delegate: self, items: objs)
  1. then you can add controller view as a child to main controller
add(child: segment, subview: backView) //this is an extension for UIViewController
  1. you need to add and conform to KFSegmentedControllerDelegate in main controller
extension ViewController : KFSegmentedControllerDelegate {
    func segmentedSelectedItem(at index: Int, obj: KFSegmentObject) {
        
    }
}

Customization

KFSetting

  • 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

KFSegmentedViewController

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

License

KFSegmentedView is released under an MIT license. See License.md for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published