OSwitch 0.2.0

OSwitch 0.2.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Nov 2016

Maintained by Oya Said.



OSwitch 0.2.0

  • By
  • Oya Said

A customizable control based on the UISwitch writen in Objective C inspired by the DVSwitch

Animated presentation of the switch

Usage

First import!

#import "OSwitch/OSwitch.h"

The control can be added in the storyboard/nib or programmatically.

Adding with storyboard

  • Add a UIView in the storyboard/nib file
  • Identity Inspector-> Change the class name to OSwitch

Adding programmatically

  • In your View Controller addopt the "OSwitchDelegate" protocol
  • Add
OSwitch *oSwitch = [[OSwitch alloc] initWithFrame:CGRectMake(0, 300, 300, 40)];
[self.view addSubview:oSwitch];

Adding the delegate

  • In your View Controller .h addopt the "OSwitchDelegate" protocol
  • Set the delegate in the View Controller
oSwitch.delegate = self;
  • Implement following methods in the .m file
- (NSArray *)titlesInSwitch:(OSwitch *)switchView {
    //TODO: return list of titles for the control here
    return titles;
}
- (void)switchView:(OSwitch *)switchView valueDidChangeAtIndex:(NSUInteger)index {
   //TODO: do stuff here
}

Customizing

You can customize bunch of stuff:

  • UIColor *backgroundColor - color of the controls background
  • UIColor *sliderColor - color of slider
  • UIColor *textColor - color of text when outside of slider
  • UIColor *selectedTextColor - color of text when slider hovers over it
  • CGFloat cornerRadius - corner radius of control and corner radius of slider
  • CGFLoat offset - pixel offset in points between the slider and the edge of control