Coder Social home page Coder Social logo

sevenswitch's Introduction

SevenSwitch

iOS7 style drop in replacement for UISwitch

Changes in this fork:

  • Carthage support
  • Swift 4.2 support

Animation

Default

Usage

Carthage

github "pykaso/SevenSwitch" ~> 2.2

Cocoapods

pod 'SevenSwitch', '~> 2.1'

Swift support was added in version 2.0. If your project does not support swift you can use 1.4.

Without Cocoapods

Add SevenSwitch.swift to your project and add the QuartzCore framework to your project.

Examples

Initializing and adding the switch to the screen

let mySwitch = SevenSwitch()
self.view.addSubview(mySwitch)

When the user manipulates the switch control ("flips" it) a UIControlEvents.valueChanged event is generated.

mySwitch.addTarget(self, action: #selector(ViewController.switchChanged(_:)), for: UIControlEvents.valueChanged)

You can set images for the on/off states

mySwitch.offImage = UIImage(named: "cross.png")
mySwitch.onImage = UIImage(named: "check.png")
mySwitch.thumbImage = UIImage(named: "thumb.png")

You can set text for the on/off states

mySwitch.offLabel.text = "ON"
mySwitch.onLabel.text = "OFF"

You can also customize the switches colors

mySwitch.thumbTintColor = UIColor(red: 0.19, green: 0.23, blue: 0.33, alpha: 1)
mySwitch.activeColor =  UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch.inactiveColor =  UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch.onTintColor =  UIColor(red: 0.45, green: 0.58, blue: 0.67, alpha: 1)
mySwitch.borderColor = UIColor.clear
mySwitch.shadowColor = UIColor.black

You can resize the switch frame to whatever you like to make fatter/skinnier controls

mySwitch.frame = CGRect(x: 0, y: 0, width: 100, height: 50)

You can turn off the rounded look by setting the isRounded property to false

mySwitch.isRounded = false

Swift and Objective-C compatability

SevenSwitch uses Swift as of its 2.0 release. SevenSwitch.swift can be used in Objective-C. See ViewController.m for an example.

Requirements

SevenSwitch requires iOS 8.0 and above.

ARC

SevenSwitch uses ARC as of its 1.0 release.

License

Made available under the MIT License. Attribution would be nice.

sevenswitch's People

Contributors

bvogelzang avatar zebra-lukas avatar cmds4410 avatar chingjun avatar dark2torch avatar andreamazz avatar gavinbunney avatar youknowone avatar mjarvis avatar mxcl avatar ric2z avatar lidbetter avatar

Watchers

Emil avatar James Cloos avatar Piotr Bernad avatar Hubert Drag avatar Mateusz Zagórski avatar Szymon Mrozek avatar Mateusz 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.