{"id":2785,"url":"https://github.com/andreamazz/ViralSwitch","last_synced_at":"2025-08-03T12:31:10.613Z","repository":{"id":21533004,"uuid":"24852295","full_name":"andreamazz/ViralSwitch","owner":"andreamazz","description":"A UISwitch that infects its superview with its tint color. ","archived":false,"fork":false,"pushed_at":"2018-12-29T00:52:42.000Z","size":1185,"stargazers_count":332,"open_issues_count":1,"forks_count":25,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-24T22:02:56.437Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreamazz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-06T15:44:38.000Z","updated_at":"2024-07-11T15:52:13.000Z","dependencies_parsed_at":"2022-08-21T17:40:15.623Z","dependency_job_id":null,"html_url":"https://github.com/andreamazz/ViralSwitch","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreamazz%2FViralSwitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreamazz%2FViralSwitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreamazz%2FViralSwitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreamazz%2FViralSwitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreamazz","download_url":"https://codeload.github.com/andreamazz/ViralSwitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228543114,"owners_count":17934427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:22.792Z","updated_at":"2024-12-07T00:30:54.901Z","avatar_url":"https://github.com/andreamazz.png","language":"Objective-C","funding_links":["https://www.paypal.me/andreamazzini"],"categories":["UI"],"sub_categories":["Switch","Layout","Other free courses"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"420\" height=\"240\" src=\"assets/logo.png\"/\u003e\n\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/andreamazz/ViralSwitch.png)](https://travis-ci.org/andreamazz/ViralSwitch)\n[![CocoaPods](https://cocoapod-badges.herokuapp.com/v/AMViralSwitch/badge.png?style=flat)](http://cocoapods.org/?q=amviralswitch)\n[![Coverage Status](https://coveralls.io/repos/andreamazz/ViralSwitch/badge.svg)](https://coveralls.io/r/andreamazz/ViralSwitch)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nUISwitch subclass that 'infects' the parent view with the `onTintColor` when the switch is turned on. Inspired by [this Dribble](https://dribbble.com/shots/1749645-Contact-Sync) by [Ramotion](https://dribbble.com/teams/Ramotion).\n\n\u003cp align=\"center\"\u003e\n  \u003ca href='https://appetize.io/app/0c9gj9epg9bnv87c4mu94udcfr' alt='Live demo'\u003e\n    \u003cimg width=\"50\" height=\"60\" src=\"assets/demo.png\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# Screenshot\n![ViralSwitch](https://raw.githubusercontent.com/andreamazz/ViralSwitch/master/assets/screenshot.gif)\n\n# Installation\n\n## Using cocoapods:\n```\npod 'AMViralSwitch'\n```\n\n## Using Carthage:\n```\ngithub \"andreamazz/ViralSwitch\"\n```\n\n# Usage\n`AMViralSwitch` is a drop-in replacement of `UISwitch`:  \n- Use `AMViralSwitch` instead of `UISwitch`\n- Set the `onTintColor` property of the switch\n\nThe switch will automatically _infect_ its superview with the selected color.\n\n## Animation duration\nUse `animationDuration` property to control the animation's speed:\n```swift\nself.toggle.animationDuration = 1.0\n```\n\n## Animation completion\nYou can set a completion block for both `on` and `off` animations:\n```swift\nself.toggle.completionOn = {\n  print(\"Enabled\")\n}\n\nself.toggle.completionOff = {\n  print(\"Disabled\")\n}\n```\n\n# Animate views\nYou can animate other views alongside the switch _infection_. Typically you'll want to change color to views or labels that are inside the same superview. You can animate CoreAnimation properties likes this:\n\n### Swift\n```swift\ntoggle.animationElementsOn = [\n    [\n        AMElementView: self.greenView.layer,\n        AMElementKeyPath: \"backgroundColor\",\n        AMElementFromValue: UIColor.blackColor().CGColor,\n        AMElementToValue: UIColor.whiteColor().CGColor\n    ]\n]\n```\n\n### Objective-C\n```objc\nself.toggle.animationElementsOn = @[\n   @[ AMElementView: self.greenView.layer,\n      AMElementKeyPath: @\"backgroundColor\",\n      AMElementFromValue: (id)[UIColor clearColor].CGColor,\n      AMElementToValue: (id)[UIColor whiteColor].CGColor }\n];\n```\n\nTo animate the `textColor` of an `UILabel` the syntax is slightly different:\n\n### Swift\n```swift\ntoggle.animationElementsOn = [\n    [\n        AMElementView: label,\n        AMElementKeyPath: \"textColor\",\n        AMElementFromValue: UIColor.blackColor(),\n        AMElementToValue: UIColor.whiteColor()\n    ]\n]\n```\n\n### Objective-C\n```objc\nself.blueSwitch.animationElementsOn = @[\n    @{ AMElementView: self.blueLabel,\n       AMElementKeyPath: @\"textColor\",\n       AMElementToValue: [UIColor whiteColor] }\n];\n```\n\nFollow the same principle to animate the `tintColor` of your `UIButton`s:\n\n### Swift\n```swift\ntoggle.animationElementsOn = [\n    [\n        AMElementView: self.infoButton,\n        AMElementKeyPath: \"tintColor\",\n        AMElementToValue: UIColor.whiteColor()\n    ]\n]\n```\n\n### Objective-C\n```objc\nself.blueSwitch.animationElementsOn = @[\n    @{ AMElementView: self.infoButton,\n       AMElementKeyPath: @\"tintColor\",\n       AMElementToValue: [UIColor whiteColor] }\n];\n```\n\n# Author\n[Andrea Mazzini](https://twitter.com/theandreamazz). I'm available for freelance work, feel free to contact me.\n\nWant to support the development of [these free libraries](https://cocoapods.org/owners/734)? Buy me a coffee ☕️ via [Paypal](https://www.paypal.me/andreamazzini).  \n\n# Contributors\nThanks to [everyone](https://github.com/andreamazz/ViralSwitch/graphs/contributors) kind enough to submit a pull request.\n\n# MIT License\n\n\tCopyright (c) 2017 Andrea Mazzini. All rights reserved.\n\n\tPermission is hereby granted, free of charge, to any person obtaining a\n\tcopy of this software and associated documentation files (the \"Software\"),\n\tto deal in the Software without restriction, including\n\twithout limitation the rights to use, copy, modify, merge, publish,\n\tdistribute, sublicense, and/or sell copies of the Software, and to\n\tpermit persons to whom the Software is furnished to do so, subject to\n\tthe following conditions:\n\n\tThe above copyright notice and this permission notice shall be included\n\tin all copies or substantial portions of the Software.\n\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n\tOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\tMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\tIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\tCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\tTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\tSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreamazz%2FViralSwitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreamazz%2FViralSwitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreamazz%2FViralSwitch/lists"}