Latest 0.2.0
Homepage https://github.com/OyaSaid/OSwitch
License MIT
Platforms ios 7.0, requires ARC
Authors

Issues
License

CocoaPods
CocoaPods
CocoaPods Version

CocoaPods Downloads

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

Animated presentation of the switch

Instalation

CocoaPods

Add the line below to your Podfile:
pod 'OSwitch'

Manually

Add the file OSwitch.m and OSwitch.h to your project.

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

License

OSwitch is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "OSwitch",
    "version": "0.2.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "OSwitch is a customisable switch control writen in Objective C.",
    "homepage": "https://github.com/OyaSaid/OSwitch",
    "authors": {
        "Oya Said": "[email protected]"
    },
    "source": {
        "git": "https://github.com/OyaSaid/OSwitch.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "ios": {
        "frameworks": [
            "UIKit",
            "Foundation"
        ]
    },
    "source_files": "OSwitch/Classes/**/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This