{"id":16903213,"url":"https://github.com/hituziando/mkatogglebutton","last_synced_at":"2026-05-06T21:46:26.909Z","repository":{"id":62446824,"uuid":"170483468","full_name":"HituziANDO/MKAToggleButton","owner":"HituziANDO","description":"MKAToggleButton is the button has multiple states for iOS.","archived":false,"fork":false,"pushed_at":"2020-02-14T03:30:07.000Z","size":612,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T15:16:21.012Z","etag":null,"topics":["button","ios","library","objective-c","swift","toggle","toggle-button","ui","view"],"latest_commit_sha":null,"homepage":"","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/HituziANDO.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-02-13T09:54:42.000Z","updated_at":"2020-02-14T03:30:10.000Z","dependencies_parsed_at":"2022-11-01T23:01:11.327Z","dependency_job_id":null,"html_url":"https://github.com/HituziANDO/MKAToggleButton","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HituziANDO%2FMKAToggleButton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HituziANDO%2FMKAToggleButton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HituziANDO%2FMKAToggleButton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HituziANDO%2FMKAToggleButton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HituziANDO","download_url":"https://codeload.github.com/HituziANDO/MKAToggleButton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244637098,"owners_count":20485446,"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":["button","ios","library","objective-c","swift","toggle","toggle-button","ui","view"],"created_at":"2024-10-13T18:11:49.010Z","updated_at":"2026-05-06T21:46:26.685Z","avatar_url":"https://github.com/HituziANDO.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"MKAToggleButton\n===\n\nMKAToggleButton is the button has multiple states for iOS. See following samples.\n\n\u003cimg src=\"./README/toggle1.gif\"/\u003e\u003cimg src=\"./README/toggle2.gif\"/\u003e\u003cimg src=\"./README/toggle3.gif\"/\u003e\u003cimg src=\"./README/toggle4.gif\"/\u003e\n\n## Get Started\n### Install Framework to Your iOS App\n\nYou have two ways to install this framework.\n\n#### 1. CocoaPods\n\nMKAToggleButton is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"MKAToggleButton\"\n```\n\n#### 2. Manual Installation\n\n1. Download latest [MKAToggleButton](https://github.com/HituziANDO/MKAToggleButton/releases)\n1. Drag \u0026 Drop MKAToggleButton.framework into your Xcode project\n\n### Quick Usage\n\n1. Import the framework\n\t\n\t```swift\n\timport MKAToggleButton\n\t```\n\t\n2. Create an instance\n\t\n\t```swift\n\tprivate lazy var toggleButton: MKAIconToggleButton = {\n        // Creates an instance with options.\n        let button = MKAIconToggleButton(items: [MKAToggleItem(image: UIImage(named: \"circle\"), title: \"Circle\"),\n                                                 MKAToggleItem(image: UIImage(named: \"square\"), title: \"Square\"),\n                                                 MKAToggleItem(image: UIImage(named: \"triangle\"), title: \"Triangle\"),\n                                                 MKAToggleItem(image: UIImage(named: \"star\"), title: \"Start\")],\n                                         font: UIFont.systemFont(ofSize: 40.0, weight: .bold),\n                                         color: .gray)\n\n        // Should use the click handler for user interaction.\n        button.onClicked = { button in\n            // `currentStateIndex` property returns the current state.\n            // The toggle button automatically increments the state each time it is clicked.\n            // When the current state is last, the next state is rewinded to the first.\n            print(\"index=\\(button.currentStateIndex)\")\n        }\n\n        // Sets the initial state. By default, the initial state index is zero.\n        button.currentStateIndex = 1\n\n        return button\n    }()\n\t```\n\t\n1. Add the toggle button to a parent view\n\t\n\t```swift\n\toverride func viewDidLoad() {\n        super.viewDidLoad()\n\n        self.view.addSubview(self.toggleButton)\n   }\n\t```\n\t\n## Use the toggle button in the storyboard\n\nYou can use the MKAToggleButton in the storyboard. The usage is following.\n\n1. Set `MKAIconToggleButton` class to Custom Class field in the storyboard\n\t\n\t\u003cimg src=\"./README/setup1.png\"/\u003e\n\t\n2. Set multiple image file names separated by commas to Image Names field\n\t\n\t\u003cimg src=\"./README/setup2.png\"/\u003e\n\t\n## Options\n### Template Rendering Mode\n\nWhen the template mode is enabled, the toggle button applies its tintColor to the icon images.\n\n```swift\n// Use the template rendering mode and set a color to `tintColor`.\ntoggleButton.isImageTemplate = true\ntoggleButton.tintColor = UIColor(red: 241.0 / 255.0, \n                                 green: 196.0 / 255.0, \n                                 blue: 15.0 / 255.0, \n                                 alpha: 1.0)\n```\n\n### Extend Touchable Area\n\nYou can extend touchable area of the button. Set `touchableExtensionXxxx` properties.\n\n```swift\nbutton.touchableExtensionTop = 16.0\nbutton.touchableExtensionLeft = 40.0\nbutton.touchableExtensionBottom = 16.0\nbutton.touchableExtensionRight = 40.0\n```\n\n### Long Press Event Handler\n\nYou can set the event handler that handle the long press event.\n\n```swift\nbutton.longPressGesture.minimumPressDuration = 1.0\nbutton.onLongPressBegan = { print(\"Began index=\\($0.currentStateIndex)\") }\nbutton.onLongPressChanged = { print(\"Changed index=\\($0.currentStateIndex)\") }\nbutton.onLongPressEnded = { print(\"Ended index=\\($0.currentStateIndex)\") }\nbutton.onLongPressCancelled = { print(\"Cancelled index=\\($0.currentStateIndex)\") }\n```\n\n----\n\nMore info, see my [sample code](https://github.com/HituziANDO/MKAToggleButton/blob/master/Sample/MKAToggleButtonSwiftSample/ViewController.swift).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhituziando%2Fmkatogglebutton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhituziando%2Fmkatogglebutton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhituziando%2Fmkatogglebutton/lists"}