https://github.com/qiudaniel/dqsegmentedcontrol
A drop-in replacement for UISegmentedControl mimicking the style of the segmented control
https://github.com/qiudaniel/dqsegmentedcontrol
hmsegmentedcontrol segmentcontrol swift
Last synced: 11 months ago
JSON representation
A drop-in replacement for UISegmentedControl mimicking the style of the segmented control
- Host: GitHub
- URL: https://github.com/qiudaniel/dqsegmentedcontrol
- Owner: QiuDaniel
- License: mit
- Created: 2019-04-07T05:54:52.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-30T09:04:03.000Z (over 6 years ago)
- Last Synced: 2025-02-27T09:24:43.865Z (12 months ago)
- Topics: hmsegmentedcontrol, segmentcontrol, swift
- Language: Swift
- Size: 515 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DQSegmentedControl
A drop-in replacement for UISegmentedControl mimicking the style of the segmented control
# Features
- Supports text
- Supports advanced title styling with text attributes for font, color, kerning, shadow, etc.
- Supports selection indicator both on top and bottom
- Works with ARC and iOS >= 9
## Todo
- Supports images
# Installation
### CocoaPods
The easiest way of installing DQSegmentedControl is via [CocoaPods](http://cocoapods.org/).
```
Normal:
pod 'DQSegmentedControl'
Support RxSwift:
pod 'DQSegmentedControl/Rx'
```
# Usage
The code below will create a segmented control with the default looks:
``` Swift
let control = DQSegmentedControl(frame: CGRect(x: 0, y: 34, width: UIScreen.main.bounds.width, height: 60))
control.sectionTitles = ["大前天","前天", "昨天", "今天", "明天", "后天", "大后天"]
control.delegate = self
control.titleTextAttributes = [.font: UIFont.systemFont(ofSize: 16),.foregroundColor:UIColor.black]
control.selectedTitleTextAttributes = [.font: UIFont.boldSystemFont(ofSize: 16),.foregroundColor:UIColor.red]
control.selectionIndicatorHeight = 2
control.selectionIndicatorColor = UIColor.red
control.selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -10, right: 0);
view.addSubview(control)
```
# RxSwift
Now SegmentedControlDelegate supports RxSwift, It can be use looks like:
``` Swift
segmentControl.rx.didSelectedAt.subscribe(onNext: { index in
print("selectedAt======>\(index)")
}).disposed(by: disposeBag)
```
Included is a demo project showing how to fully customise the control.

## Special Thanks to [@HeshamMegid](http://twitter.com/HeshamMegid), the project refer to his HMSegmentedControl much more.
# License
DQSegmentedControl is licensed under the terms of the MIT License. Please see the [LICENSE](LICENSE.md) file for full details.