Nicely animated flat design switch alternative to UISwitch

Overview

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

Comments
  • Improve accessibility by announcing changed values

    Improve accessibility by announcing changed values

    This change announces the changed value. I do it in the animation check because it's not necessary to announce the value change during initialization. If you want to suggest a better way to do this, I'm open to ideas.

    opened by marcuswu 5
  • Inner color branch

    Inner color branch

    Hey,

    Regarding this point:

    • Make sure the Example project compiles and works fine in the Simulator

    I tried it, it always shows black color!

    It worked perfectly before adding the changes you asked for. Any suggestion? Did I forget something?

    opened by Maryom 4
  • animation callbacks

    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.

    opened by vitobellini 4
  • Tap event not working in Swift 1.3

    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!

    opened by rishimukherjee 2
  • Min Deployment Target 8.0 = Warning in Xcode

    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

    opened by nilsnilsnils 1
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 1
  • Manual Installation

    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.

    opened by lfarah 1
  • OnSwitchValueChanged cast issue

    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?

    opened by Alex-Catchpole 1
  • Exceeds the size of the view by 1

    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

    opened by dehlen 0
Releases(1.0.8)
Owner
null
A Swift material design UI module which paints over the parent view when the switch is on.

A Swift material design UI module which paints over the parent view when the switch is on. We specialize in the designing and coding of c

Ramotion 2.9k Dec 29, 2022
A Customizable Switch UI for iOS, Inspired from Google's Material Design

Overview JTMaterialSwitch is google's material design like switch UI with animation features. This library has cool and sophisticated animations, ripp

Junichi Tsurukawa 319 Nov 28, 2022
UISwitch which paints over the parent view with the color in Swift.

AnimatedSwitch Swift subclass of the UISwitch which paints over the parent view with the color if switch is turned on and returns original superview b

Alex Sergeev 248 Jul 26, 2022
A UISwitch that infects its superview with its tint color.

UISwitch subclass that 'infects' the parent view with the onTintColor when the switch is turned on. Inspired by this Dribble by Ramotion. Screenshot I

Andrea Mazzini 337 Sep 12, 2022
iOS7 style drop in replacement for UISwitch

SevenSwitch iOS7 style drop in replacement for UISwitch Usage Cocoapods pod 'SevenSwitch', '~> 2.1' Swift support was added in version 2.0. If your p

Ben Vogelzang 779 Sep 5, 2022
πŸ’Š An iOS switch control implemented in Swift with full Interface Builder support

' :::=== ::: === === ::: :::==== :::===== ::: === ' ::: ::: === === ::: :::==== ::: ::: === ' ===== === === === === ===

Thanh Pham 145 Dec 7, 2022
An animation switch collection

TKSwitcherCollection An animate switch collection Requirements iOS 8.0+ Xcode 9.0 Swift 4.0 Installation CocoaPods You can use CocoaPods to install TK

TBXark 903 Dec 21, 2022
Project Flat iOS is the iOS client of Agora Flat open source classroom.

Agora Flat iOS Project flat is the iOS client of Agora Flat open source classroom. δΈ­ζ–‡ Features Open sourced front-end and back-end [Flat Web][flat-web

netless 24 Dec 12, 2022
Various view's effects for iOS, written in Swift. Allows you to animate views nicely with easy to use extensions

Various view's effects for iOS, written in Swift. Allows you to animate views nicely with easy to use extensions. Every animation is randomized. Currently supported animations:

Artur Rymarz 23 Aug 23, 2022
A beautiful activity indicator and modal alert written in Swift (originally developed for my app DoodleDoodle) Using blur effects, translucency, flat and bold design - all iOS 8 latest and greatest

SwiftSpinner SwiftSpinner is an extra beautiful activity indicator with plain and bold style. It uses dynamic blur and translucency to overlay the cur

Marin Todorov 2.1k Dec 19, 2022
Flat design pressable button for iOS developers.

HTPressableButton HTPressableButton is designed for iOS developers to be able to spend time developing ideas, not building basic buttons. These stylis

Famolus 859 Dec 12, 2022
Yet another animated flat buttons in Swift

DynamicButton is a powerful flat design button written in Swift to display hamburger button like with animated transitions between style updates. It a

Yannick Loriot 1.2k Jan 5, 2023
A Customizable Switch UI for iOS, Inspired from Google's Material Design in Swift

MJMaterialSwitch Overview MJMaterialSwitch is google's material design like switch UI with animation features. This library has cool and sophisticated

Jaleel Nazir 64 Jul 29, 2022
A Swift material design UI module which paints over the parent view when the switch is on.

A Swift material design UI module which paints over the parent view when the switch is on. We specialize in the designing and coding of c

Ramotion 2.9k Dec 29, 2022
A Swift material design UI module which paints over the parent view when the switch is on.

:octocat: ?? RAMPaperSwitch is a Swift material design UI module which paints over the parent view when the switch is turned on. iOS library by @Ramotion

Ramotion 2.9k Dec 29, 2022
Runkeeper design switch control

DGRunkeeperSwitch Runkeeper design switch control (two part segment control) developed in Swift 2.0 Requirements Xcode 7-beta or higher iOS 8.0 or hig

Danil Gontovnik 1.9k Dec 2, 2022
A Customizable Switch UI for iOS, Inspired from Google's Material Design

Overview JTMaterialSwitch is google's material design like switch UI with animation features. This library has cool and sophisticated animations, ripp

Junichi Tsurukawa 319 Nov 28, 2022
● β—‹ β—‹ β—‹ A nice, animated UIPageControl alternative.

Page Control Installation Usage Example import UIKit import PageControl class ViewController: UIViewController, UIScrollViewDelegate { @IBOu

Kasper Lahti 113 Sep 1, 2022
πŸ’₯ Beautiful, animated and highly customizable UIPageControl alternative for iOS.

PageControl Requirements iOS 9.0+ Xcode 7.0+ Installation CocoaPods: Add folowing line to Podfile and run 'pod instal'. pod 'Sevruk-PageControl' Or j

Sevruk Development 30 May 2, 2022