• Stars
    star
    981
  • Rank 46,671 (Top 1.0 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Nicely animated flat design switch alternative to UISwitch

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

More Repositories

1

Glide

Game engine for making 2d games on iOS, macOS and tvOS, with practical examples and tutorials
Swift
492
star
2

AICustomViewControllerTransition

Easy and tidy way for creating custom UIViewController transitions for iOS
Swift
139
star
3

AIMapViewWrapper

use Google maps zoom level with MKMapView, animated route tracking with overlay views, and some other handy MKMapView functionality
Objective-C
30
star
4

CombineOperators

Interactive tutorial/cheat sheet app that lets you play with Combine framework publishers
Swift
28
star
5

StyledMarkdown

Generate SwiftUI Text or AttributedString from markdown strings with custom style names.
Swift
22
star
6

XMLText

Generate styled SwiftUI Text from strings with XML tags.
Swift
20
star
7

AISegmentedControl

a modular and fully customizable segmented control for iOS
Objective-C
3
star
8

AINavigationItemTitleLayoutView

an abstract class for correctly doing layout of UINavigationItem titleView subviews in iOS projects
Objective-C
2
star
9

AIReleaseToRefreshWrapper

a wrapper class for adding and managing release to refresh functionality to any scroll view in iOS
Objective-C
2
star
10

earthbound-narrative

A narrative flowchart from Earthbound(1994) game
JavaScript
2
star
11

glideTutorial-characterPlatform

glide engine tutorial where you can create a walking and jumping character on a platform 📺
Swift
2
star
12

cocoatoucher.github.io

1
star
13

AIPickerViewWrapper

1
star
14

glideTutorial-2-inputIntro

glide engine tutorial where you can learn how to make touch control buttons and know more about input management in general 📺
Swift
1
star