{"id":13466577,"url":"https://github.com/amerhukic/AHDownloadButton","last_synced_at":"2025-03-25T21:32:37.523Z","repository":{"id":42597124,"uuid":"148006287","full_name":"amerhukic/AHDownloadButton","owner":"amerhukic","description":"Customizable download button with progress and transition animations. It is based on Apple's App Store download button.","archived":false,"fork":false,"pushed_at":"2022-01-26T11:31:43.000Z","size":311,"stargazers_count":481,"open_issues_count":1,"forks_count":58,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-01T04:07:52.796Z","etag":null,"topics":["animation","button","download","downloadbutton","ios","ios11","swift","ui"],"latest_commit_sha":null,"homepage":"https://www.amerhukic.com/replicating-app-store-download-button","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/amerhukic.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":"2018-09-09T08:19:22.000Z","updated_at":"2024-07-31T02:22:46.000Z","dependencies_parsed_at":"2022-07-09T15:18:12.974Z","dependency_job_id":null,"html_url":"https://github.com/amerhukic/AHDownloadButton","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerhukic%2FAHDownloadButton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerhukic%2FAHDownloadButton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerhukic%2FAHDownloadButton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerhukic%2FAHDownloadButton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amerhukic","download_url":"https://codeload.github.com/amerhukic/AHDownloadButton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222092150,"owners_count":16929797,"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":["animation","button","download","downloadbutton","ios","ios11","swift","ui"],"created_at":"2024-07-31T15:00:46.631Z","updated_at":"2024-10-29T18:32:06.085Z","avatar_url":"https://github.com/amerhukic.png","language":"Swift","funding_links":[],"categories":["Libs","UI [🔝](#readme)"],"sub_categories":["UI"],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/amerhukic/AHDownloadButton/master/Logo.png\" width=\"420\" max-width=\"80%\" alt=\"Logo\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Swift-5.0-orange.svg\" /\u003e\n    \u003ca href=\"https://cocoapods.org/pods/AHDownloadButton\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/v/AHDownloadButton.svg?style=flat\" alt=\"Pod Version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://img.shields.io/badge/Swift_Package_Manager-compatible-orange\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift_Package_Manager-compatible-orange\" alt=\"SPM compatible\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage compatible\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Licence-MIT-green.svg\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/hukicamer\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/contact-%40hukicamer-blue.svg?style=flat\" alt=\"Twitter: @hukicamer\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n**AHDownloadButton** is a customizable download button similar to the download button in the latest version of Apple's App Store app (since iOS 11).\nIt features download progress animation as well as animated transitions between download states: start download, pending, downloading and downloaded. [You can find more details about the implementation on my blog](https://amerhukic.com/replicating-app-store-download-button).\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/amerhukic/AHDownloadButton/master/Demo.gif\"/\u003e\n\u003c/p\u003e\n\n## Requirements\n\n- iOS 8.0+\n- Xcode 10.2+\n- Swift 5.0+\n\n## Usage\n\n### Code\nTo use `AHDownloadButton` in code, you simply create a new instance and add it as a subview to your desired view:\n```swift\n  let downloadButton = AHDownloadButton()\n  downloadButton.frame = CGRect(origin: origin, size: size)\n  view.addSubview(downloadButton)\n```\nThe button can have 4 different states:\n- `startDownload` - initial state before downloading\n- `pending` - state for preparing for download\n- `downloading` - state when the user is downloading\n- `downloaded` - state when the user finished downloading\n\nThe state of the button can be changed through its `state` property.\n\n### Delegate\nYou can use the `AHDownloadButtonDelegate` to monitor taps on the button and update button's state if needed. To update the current download progress, use the `progress` property. Here is an example how it could be implemented:  \n\n```swift\nextension DownloadViewController: AHDownloadButtonDelegate {\n\n    func downloadButton(_ downloadButton: AHDownloadButton, tappedWithState state: AHDownloadButton.State)\n        switch state {\n        case .startDownload:\n\n            // set the download progress to 0\n            downloadButton.progress = 0\n\n            // change state to pending and wait for download to start\n            downloadButton.state = .pending\n\n            // initiate download and update state to .downloading\n            startDownloadingFile()\n\n        case .pending:\n\n            // button tapped while in pending state\n            break\n\n        case .downloading:\n\n            // button tapped while in downloading state - stop downloading\n            downloadButton.progress = 0\n            downloadButton.state = .startDownload\n\n        case .downloaded:\n\n            // file is downloaded and can be opened\n            openDownloadedFile()\n\n        }\n    }\n}\n```\n\nYou can also use closures instead of the `AHDownloadButtonDelegate` by setting the `didTapDownloadButtonAction` and `downloadButtonStateChangedAction` properties.\n\n### Customisation\n\n`AHDownloadButton` can be customized. These are the properties that can be used for customizing the button:\n\n1.  Use the custom initializer  `init(alignment: HorizontalAlignment)` to set the horizontal alignment property. `HorizontalAlignment` determines the position of the pending and downloading circles. The position can either be  `center` , `left` or `right`. The default value is `center`.\n\n\n2. Customization properties when button is in `startDownload` state:\n\n  - `startDownloadButtonTitle` - button's title\n  - `startDownloadButtonTitleFont` - button's title font\n  - `startDownloadButtonTitleSidePadding` - padding for left and right side of button's title\n  - `startDownloadButtonHighlightedBackgroundColor` - background color for the button when it's in highlighted state (when the user presses the button)\n  - `startDownloadButtonNonhighlightedBackgroundColor` - background color for the button when it's in nonhighlighted state (when the button is not pressed)\n  - `startDownloadButtonHighlightedTitleColor` - title color for the button when it's in highlighted state (when the user presses the button)\n  - `startDownloadButtonNonhighlightedTitleColor` - title color for the button when it's in nonhighlighted state (when the button is not pressed)\n\n\n3. Customization properties when button is in `pending` state:\n\n  - `pendingCircleColor` - color of the pending circle\n  - `pendingCircleLineWidth` - width of the pending circle\n\n\n4. Customization properties when button is in `downloading` state:\n\n  - `downloadingButtonHighlightedTrackCircleColor` - color for the track circle when it's in highlighted state (when the user presses the button)\n  - `downloadingButtonNonhighlightedTrackCircleColor` - color for the track circle when it's in nonhighlighted state (when the button is not pressed)\n  - `downloadingButtonHighlightedProgressCircleColor` - color for the progress circle when it's in highlighted state (when the user presses the button)\n  - `downloadingButtonNonhighlightedProgressCircleColor` - color for the progress circle when it's in nonhighlighted state (when the button is not pressed)\n  - `downloadingButtonHighlightedStopViewColor` - color for the stop view in the middle of the progress circle when it's in highlighted state (when the user presses the button)\n  - `downloadingButtonNonhighlightedStopViewColor` - color for the stop view in the middle of the progress circle when it's in nonhighlighted state (when the button is not pressed)\n  - `downloadingButtonCircleLineWidth` -  width of the downloading circle\n\n\n5. Customization properties when button is in `downloaded` state:\n\n  - `downloadedButtonTitle` - button's title\n  - `downloadedButtonTitleFont` - button's title font\n  - `downloadedButtonTitleSidePadding` - padding for left and right side of button's title\n  - `downloadedButtonHighlightedBackgroundColor` - background color for the button when it's in highlighted state (when the user presses the button)\n  - `downloadedButtonNonhighlightedBackgroundColor` - background color for the button when it's in nonhighlighted state (when the button is not pressed)\n  - `downloadedButtonHighlightedTitleColor` - title color for the button when it's in highlighted state (when the user presses the button)\n  - `downloadedButtonNonhighlightedTitleColor` - title color for the button when it's in nonhighlighted state (when the button is not pressed)\n  \n6. `transitionAnimationDuration` - animation duration between the different states of the button\n  \n### Special note\n\n`AHDownloadButton` in `startDownload` and `downloaded` states calculates its width based on **button title**. Use the `startDownloadButtonTitleSidePadding` and `downloadedButtonTitleSidePadding` properties to customise the width when the button is in the aforementioned states.\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate AHDownloadButton into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\ntarget '\u003cYour Target Name\u003e' do\n    pod 'AHDownloadButton'\nend\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate AHDownloadButton into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"amerhukic/AHDownloadButton\" ~\u003e 1.3.0\n```\n\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.\n\nOnce you have your Swift package set up, adding AHDownloadButton as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/amerhukic/AHDownloadButton\", .upToNextMajor(from: \"1.3.0\"))\n]\n```\n\n## Author\n\n[Amer Hukić](https://amerhukic.com)\n\n## License\n\nAHDownloadButton is licensed under the MIT license. Check the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famerhukic%2FAHDownloadButton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famerhukic%2FAHDownloadButton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famerhukic%2FAHDownloadButton/lists"}