TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | May 2016 |
Maintained by tauCross.
Customizable control based on UISwitch and UISegmentedControl written in Objective-C
DVSwitch was inspired by UISwitch and UISegmentedControl. The goals of this code are:
Slider is halfway from one item to another, notice per pixel text color change
DVSwitch *switcher = [[DVSwitch alloc] initWithStringsArray:@[@"First", @"Second"]];
switcher.frame = CGRectMake(20, 60, self.view.frame.size.width - 40, 34);
[self.view addSubview:switcher];
[switcher setPressedHandler:^(NSUInteger index) {
NSLog(@"Did switch to index: %lu", (unsigned long)index);
}];
Customizable properties:
UIColor *backgroundColor
- color of the controls backgroundUIColor *sliderColor
- color of sliderUIColor *labelTextColorInsideSlider
- color of text when slider hovers over itUIColor *labelTextColorOutsideSlider
- color of text when outside of sliderUIFont *font
- font used in controlCGFloat cornerRadius
- corner radius of control and corner radius of sliderCGFLoat sliderOffset
- pixel offset in points between the slider and the edge of controlWhen the user taps or slides the control, handler block is getting called with the index of element which was triggered. To set it use the following method:
- (void)setPressedHandler:(void (^)(NSUInteger index))handler;
Source code contains example project with few different types of switch.
iOS 7.0 and Xcode 6.0
The control might work on earlier versions, but this was not tested.
1.0.1 - Added method to change index without calling completion block.
1.0.0 - Initial version.
We will welcome any feedback or pull requests to the project. Any changes should NOT change already working behaviour and API. Additions are welcome.
Version: 1.0.1
License: MIT
Stas Zhukovskiy
René Fouquet
Dmitry Volevodz