Git Product home page Git Product logo

aiflatswitch's Introduction

AIFlatSwitch

A smooth, nice looking and IBDesignable flat design switch for iOS. Can be used instead of UISwitch.

Inspired by Creativedash's Dribbble post here

Flat switch animation

cocoapods

Requirements

  • iOS 8.0+, tvOS 12.0+
  • Xcode 11.0+
  • Swift 5

Usage

Creating the flat switch

  • Either programmatically
var flatSwitch = AIFlatSwitch(frame: CGRectMake(0, 0, 50, 50))
  • Or in Interface Builder

Methods

To change its selected state:

flatSwitch.isSelected = true
  • IBInspectable

or:

flatSwitch.setSelected(true, animated: true)

To listen to its state changes:

@IBAction func handleSwitchValueChange(sender: AnyObject) {
		if let flatSwitch = sender as? AIFlatSwitch {
			print(flatSwitch.isSelected)
		}
	}

Animation observer callbacks:

flatSwitch.selectionAnimationDidStart = { isSelected in
    print("New state: \(isSelected)")
}

flatSwitch.selectionAnimationDidStop = { isSelected in
    print("State when animation stopped: \(isSelected)")
}

Styling the switch:

flatSwitch.lineWidth = 2.0
flatSwitch.strokeColor = UIColor.blue
flatSwitch.trailStrokeColor = UIColor.red
flatSwitch.backgroundLayerColor = UIColor.red
flatSwitch.animatesOnTouch = false
  • IBInspectable

Contribution guidelines

  • Make your changes in your branch
  • Bump the pod version in AIFlatSwitch.podspec file (e.g. 1.0.1 to 1.0.2)
  • Make sure the Example project compiles and works fine in the Simulator
  • Find references to your source code changes in README.md and update them (e.g. method names, changed features)
  • Create a pull request

License

AIFlatSwitch is released under the MIT license. See LICENSE for details.

animated check button, checkmark

aiflatswitch's People

Contributors

bryant1410 avatar cocoatoucher avatar darkkrye avatar dehlen avatar donvaughn avatar maryom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aiflatswitch's Issues

Inner circle color

Hey,

Thanks for your work.

Is there a way to set a color just for the inner circle?

Exceeds the size of the view by 1

Hello,
I really like your library however I just encountered a litte UI-Bug. The drawn uicontrol is too big by 1 pixel for the containing UIView. You can see this behaviour in your example application:
bildschirmfoto 2015-10-24 um 15 11 01

However when running the application it looks normal because the background color of the views are the same. But in my situtation the views background color's were not the same.

I will make a PR to fix this problem.
Feel free to merge.

Best Regards,
David

Min Deployment Target 8.0 = Warning in Xcode

AIFlatSwitch/Package.swift The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.5.99.

Maybe someone can set the min version for iOS to 9.0 ? :) Thanks

OnSwitchValueChanged cast issue

The example you provided for OnSwitchValueChanged doesn't seem to work. The casting will always fail. When trying to implicitly cast as AIFlatSwitch like so I get an error.

//Cast
let coolSwitch = sender as! AIFlatSwitch

//Error
Could not cast value of type 'AIFlatSwitch.AIFlatSwitch' (0x23c588) to 'aiflatswitch.AIFlatSwitch' (0xc8428).

Is this a bug or am I doing something wrong?

animation callbacks

Hello, it would be nice to have a callback blocs for animation did start and animation did end.
What do you think? I have to address this scenario:

I've got the switches tableview's rows, and when the switch changes from off to on, I have to reorder the table, but the animation during the reording is not fine.

Tap event not working in Swift 1.3

The function onTouchUpInside is not getting called. I am making the switch programmatically. I am using Swift 1.3. Could not understand why it is not working. Please help!

Manual Installation

CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

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.