Coder Social home page Coder Social logo

dvswitch's Introduction

DVSwitch

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
  • Supporting pan or swipe interactions
  • Requires very little setup - images are not needed
  • Beautiful font color inversion effect - label color changes per pixel:
  • Automatic adjustment based on number of items

Slider is halfway from one item to another, notice per pixel text color change

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);
    
}];

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.

Changelog

1.0.1 - Added method to change index without calling completion block.
1.0.0 - Initial version.

Support

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

Contributors:

Stas Zhukovskiy
René Fouquet
Dmitry Volevodz

--

dvswitch's People

Contributors

fouquet avatar voley avatar zhukn1 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.