Skip to content
forked from Voley/DVSwitch

Customizable control based on UISwitch and UISegmentedControl written in Objective-C.

License

Notifications You must be signed in to change notification settings

shiratsu/DVSwitch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

DVSwitch

Flexible and customizable control based on UISwitch and UISegmentedControl written in Objective-C.

DVSwitch was inspired by UISwitch and UISegmentedControl. The goals of this code are:

  • Easily customizable control with nice animations
  • Beautiful font color inversion effect - label color changes per pixel
  • Supporting pan or swipe interactions
  • Requires very little setup - images are not needed

Usage

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);
    
}];
[self.view addSubview:switcher];

Customizable properties:

  • UIColor *backgroundColor - color of the controls background
  • UIColor *sliderColor - color of slider
  • UIColor *labelTextColorInsideSlider - color of text when slider hovers over it
  • UIColor *labelTextColorOutsideSlider - color of text when outside of slider
  • UIFont *font - font used in control
  • CGFloat cornerRadius - corner radius of control and corner radius of slider
  • CGFLoat sliderOffset - pixel offset in points between the slider and the edge of control

When 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.

Requirements:

iOS 7.0 and Xcode 6.0

The control might work on earlier versions, but this was not tested.

Support

We will welcome any feedback or pull requests to the project.

Version: 1.0.0
License: MIT

--

About

Customizable control based on UISwitch and UISegmentedControl written in Objective-C.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 97.6%
  • Ruby 2.4%