This is a custom Segmented Control with icon and text on every segment.
let segmentedControl = BMSegmentedControl(withIcon: view.bounds,
items: ["Happy", "Normal", "Sad"],
icons: [UIImage(named: "happy_gray")!, UIImage(named: "flat_gray")!, UIImage(named: "sad_gray")!],
selectedIcons: [UIImage(named: "happy_white")!, UIImage(named: "flat_white")!, UIImage(named: "sad_white")!],
backgroundColor: .white,
thumbColor: .lightGray,
textColor: .black,
selectedTextColor: .cyan,
orientation: .leftRight
)
let segmentedControl = BMSegmentedControl(withoutIcon: view.bounds,
items: titles,
backgroundColor: .white,
thumbColor: .lightGray,
textColor: .black,
selectedTextColor: .cyan
)
// To get the changed value event, set it manually on your view controller
segmentedControl.addTarget(self, action: #selector(segmentedHasChanged), for: .valueChanged)
// You need to add BMSegmnetedControl to container
view.addSubview(segmentedControl)
// You could set the selected index. Default is 0
segmentedControl.selectedIndex = 1
- iOS 8.0+
- Xcode 8
You can use CocoaPods to install BMSegmentedControl
by adding it to your Podfile
:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'BMSegmentedControl', '~> 0.4.3'
end
BMSegmentedControl is released under the MIT license. See LICENSE for details.