All Projects → steakknife → SKTogglesControl

steakknife / SKTogglesControl

Licence: other
SKTogglesControl is a customizable multiple toggle UIControl based on SVSegmentedControl

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to SKTogglesControl

PadControl
A UIControl subclass for two-dimension directional input
Stars: ✭ 59 (+103.45%)
Mutual labels:  uicontrol
UIGradientSlider
GradientSlider is a UIControl subclass which is similar to UISlider, but with a linear gradient coloring the slider’s track. Useful for creating color pickers. Initially fork of https://github.com/jonhull/GradientSlider rewritten to Obj-C
Stars: ✭ 28 (-3.45%)
Mutual labels:  uicontrol
Lgbutton
A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.
Stars: ✭ 2,216 (+7541.38%)
Mutual labels:  uicontrol
Closures
Swifty closures for UIKit and Foundation
Stars: ✭ 1,720 (+5831.03%)
Mutual labels:  uicontrol
Selector-Closure
A light way to convert objc target-action style to closure
Stars: ✭ 14 (-51.72%)
Mutual labels:  uicontrol
ContainerView
Using Container View in iOS with Swift
Stars: ✭ 34 (+17.24%)
Mutual labels:  uicontrol
ALRadioButtons
RadioButtons for iOS. Inherited from UIControl, support 2 native styles, fully customizable.
Stars: ✭ 65 (+124.14%)
Mutual labels:  uicontrol
UltraWeekCalendar
UltraWeekCalendar - Clean UI to select day through weeks
Stars: ✭ 29 (+0%)
Mutual labels:  uicontrol
LiveFader
@IBDesignable Horizontal or vertical UIControl subclass that can start from bottom or middle of the control.
Stars: ✭ 21 (-27.59%)
Mutual labels:  uicontrol

Looking for maintainers

Plz send me an email for more details

SKTogglesControl

SKTogglesControl is a customizable UIControl class that mimics UISegmentedControl but that looks like an UISwitch.

SKTogglesControl

Installation

From CocoaPods

Add this to your `Podfile:

pod 'SKTogglesControl', :podspec => 'https://raw.github.com/steakknife/SKTogglesControl/master/SKTogglesControl.podspec'

Manually

Important note if your project doesn't use ARC: you must add the -fobjc-arc compiler flag to SKTogglesControl.m and SVSegmentedThumb.m in Target Settings > Build Phases > Compile Sources.

  • Drag the SKTogglesControl/SKTogglesControl folder into your project.
  • Add the QuartzCore framework to your project.

Usage

(see sample Xcode project in /Demo)

In its simplest form, this is how you create an SKTogglesControl instance:

segmentedControl = [[SKTogglesControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"Section 1", @"Section 2", nil]];
segmentedControl.changeHandler = ^(NSUInteger newIndex, BOOL newState) {
    // respond to index change
};

[self.view addSubview:segmentedControl];

You can position it using either its frame or center property:

Customization

SKTogglesControl can be customized with the following properties:

@property (nonatomic, strong) NSArray *sectionTitles;
@property (nonatomic, strong) NSArray *sectionImages;

@property (nonatomic, readwrite) BOOL animateToInitialSelection; // default is NO

@property (nonatomic, readwrite) CGFloat minimumOverlapToChange; // default is 0.66 - Only snap to a new segment if the thumb overlaps it by this fraction
@property (nonatomic, readwrite) UIEdgeInsets touchTargetMargins; // default is UIEdgeInsetsMake(0, 0, 0, 0) - Enlarge touch target of control

@property (nonatomic, strong) UIColor *backgroundTintColor; // default is [UIColor colorWithWhite:0.1 alpha:1]
@property (nonatomic, retain) UIImage *backgroundImage; // default is nil

@property (nonatomic, readwrite) CGFloat height; // default is 32.0
@property (nonatomic, readwrite) UIEdgeInsets thumbEdgeInset; // default is UIEdgeInsetsMake(2, 2, 3, 2)
@property (nonatomic, readwrite) UIEdgeInsets titleEdgeInsets; // default is UIEdgeInsetsMake(0, 10, 0, 10)
@property (nonatomic, readwrite) CGFloat cornerRadius; // default is 4.0

@property (nonatomic, retain) UIFont *font; // default is [UIFont boldSystemFontOfSize:15]
@property (nonatomic, retain) UIColor *textColor; // default is [UIColor grayColor];
@property (nonatomic, strong) UIColor *innerShadowColor; // default is [UIColor colorWithWhite:0 alpha:0.8]
@property (nonatomic, retain) UIColor *textShadowColor;  // default is [UIColor blackColor]
@property (nonatomic, readwrite) CGSize textShadowOffset;  // default is CGSizeMake(0, -1)

Its thumb (SVSegmentedThumb) can be customized as well:

@property (nonatomic, retain) UIImage *backgroundImage; // default is nil;
@property (nonatomic, retain) UIImage *highlightedBackgroundImage; // default is nil;

@property (nonatomic, retain) UIColor *tintColor; // default is [UIColor grayColor]
@property (nonatomic, assign) UIColor *textColor; // default is [UIColor whiteColor]
@property (nonatomic, assign) UIColor *textShadowColor; // default is [UIColor blackColor]
@property (nonatomic, readwrite) CGSize textShadowOffset; // default is CGSizeMake(0, -1)
@property (nonatomic, readwrite) BOOL shouldCastShadow; // default is YES (NO when backgroundImage is set)
@property (nonatomic, assign) CGFloat gradientIntensity; // default is 0.15

To customize the thumb's appearance, you'll have to set the properties through SKTogglesControl's thumb property. For instance, setting the thumb's tintColor is done with:

segmentedControl.thumb.tintColor = someColor;

Responding to value changes

You can respond to value changes using a block handler:

segmentedControl.changeHandler = ^(NSUInteger newIndex, BOOL newState) {
    // respond to state change
};

If you haven't fallen in love with blocks yet, you can still use the classic UIControl method:

[mySegmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];

Providing an action method ending with a semicolon, the sender object is therefore made accessible:

- (void)segmentedControlChangedValue:(SKTogglesControl*)segmentedControl {
	NSLog(@"segmentedControl did select index %i state %d", segmentedControl.newIndex, segmentedControl.newState);
}

Credits

SKTogglesControl is brought to you by Barry Allard and original credit to Sam Vermette and contributors to the project. If you're using SKTogglesControl in your project, attribution would be nice.

Wanted (dead or alive)

  • Glow effect
  • Inset effect
  • Outset look (dimmed instead of missing)
  • Press animation
  • Nice sounds

Issues

http://github.com/steakknife/SKTogglesControl/issues

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].