{"id":15113934,"url":"https://github.com/sindresorhus/custombutton","last_synced_at":"2025-04-30T18:05:09.041Z","repository":{"id":63920508,"uuid":"210127863","full_name":"sindresorhus/CustomButton","owner":"sindresorhus","description":"Customizable button for your macOS app","archived":false,"fork":false,"pushed_at":"2024-02-20T07:13:01.000Z","size":511,"stargazers_count":174,"open_issues_count":0,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-30T18:05:00.262Z","etag":null,"topics":["button","cocoa","macos","nsbutton","swift","swift-package"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2019-09-22T10:20:21.000Z","updated_at":"2025-04-29T09:24:15.000Z","dependencies_parsed_at":"2024-02-26T22:12:37.940Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/CustomButton","commit_stats":{"total_commits":16,"total_committers":5,"mean_commits":3.2,"dds":0.3125,"last_synced_commit":"e7c72500005ae4f3ca29c102ad7f8175c68c396b"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FCustomButton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FCustomButton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FCustomButton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FCustomButton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/CustomButton/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758162,"owners_count":21638988,"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","cocoa","macos","nsbutton","swift","swift-package"],"created_at":"2024-09-26T01:40:33.055Z","updated_at":"2025-04-30T18:05:09.016Z","avatar_url":"https://github.com/sindresorhus.png","language":"Swift","readme":"# CustomButton\n\n\u003e Customizable button for your macOS app\n\n\u003cimg src=\"screenshot.gif\" width=\"474\" height=\"223\"\u003e\n\nIt's a layer-based NSButton subclass that animates the styles and colors between normal and active (pressed) state.\n\nThis package is used in production by [Gifski](https://github.com/sindresorhus/Gifski).\n\n## Requirements\n\n- macOS 10.13+\n\n## Install\n\nAdd `https://github.com/sindresorhus/CustomButton` in the [“Swift Package Manager” tab in Xcode](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app).\n\n## Usage\n\nSee the [source](Sources/CustomButton/CustomButton.swift) for what properties you can change and play with it in the [example app](Example). By default, it has no style.\n\n```swift\nimport Cocoa\nimport CustomButton\n\n@main\nfinal class AppDelegate: NSObject, NSApplicationDelegate {\n\t@IBOutlet weak var window: NSWindow!\n\n\tfunc applicationDidFinishLaunching(_ notification: Notification) {\n\t\tlet button = CustomButton()\n\t\tbutton.translatesAutoresizingMaskIntoConstraints = false\n\t\tbutton.title = \"CustomButton\"\n\t\tbutton.activeBackgroundColor = .systemPink\n\t\tbutton.borderWidth = 1\n\t\tbutton.borderColor = .systemPink\n\t\tbutton.cornerRadius = 5\n\t\tbutton.textColor = .systemPink\n\t\tbutton.activeTextColor = .white\n\n\t\tlet contentView = window.contentView!\n\t\tcontentView.addSubview(button)\n\n\t\tNSLayoutConstraint.activate([\n\t\t\tbutton.centerXAnchor.constraint(equalTo: contentView.centerXAnchor),\n\t\t\tbutton.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),\n\t\t\tbutton.widthAnchor.constraint(equalToConstant: 100),\n\t\t\tbutton.heightAnchor.constraint(equalToConstant: 30)\n\t\t])\n\t}\n}\n```\n\nThe button can also be edited in Interface Builder, but Xcode is very buggy with `@IBDesignable`, so I would recommend using it only programmatically for now.\n\n## FAQ\n\n#### Can you support Carthage and CocoaPods?\n\nNo, but you can still use Swift Package Manager for this package even though you mainly use Carthage or CocoaPods.\n\n#### Won't SwiftUI make this moot?\n\nSwiftUI does indeed make it much easier to create custom-looking buttons, but SwiftUI is still immature and most companies will not be able to require macOS 10.15 for a long time. So this package will still be useful for multiple years to come.\n\n## Related\n\n- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults\n- [KeyboardShortcuts](https://github.com/sindresorhus/KeyboardShortcuts) - Add user-customizable global keyboard shortcuts to your macOS app\n- [LaunchAtLogin](https://github.com/sindresorhus/LaunchAtLogin) - Add \"Launch at Login\" functionality to your macOS app\n- [DockProgress](https://github.com/sindresorhus/DockProgress) - Show progress in your app's Dock icon\n- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift+archived%3Afalse\u0026type=repositories)\n\nYou might also like my [apps](https://sindresorhus.com/apps).\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcustombutton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fcustombutton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcustombutton/lists"}