GBKUIButtonProgressView
  • November 9, 2023

Inspired by Apple’s download progress buttons in the app store

Created by @pklada and @miketsprague

Checkout the blog post.

Installation


CocoaPods

pod 'GBKUIButtonProgressView', git: 'https://github.com/Guidebook/gbkui-button-progress-view'

Manually add to your project

Just add the files in GBKUIButtonProgressView/ to your project

Usage


self.downloadButton.initialTitle = @”Download”;
self.downloadButton.completeTitle = @”Open”;

// Add a target (like a regular button)
[self.downloadButton addTarget:self action:@selector(downloadButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

-(void)downloadButtonPressed:(id)sender {
// Update the button’s state based on your downloading item’s state
if(!self.isDownloading && !self.isDownloaded) {
[self.downloadButton startProgressing];
[self downloadItem];
} else if(self.isDownloaded) {
[self openItem];
} else {
[self cancelDownloadingItem];
[self.downloadButton setProgress:0 animated:YES withCompletion:^{
[self.downloadButton reset];
}];
}
}

-(void)downloadProgressed:(CGFloat)progress {
// Update the download button’s progress when you get a progress update from your item
[self.downloadButton setProgress:progress animated:YES];
}

To change the tint color, simply:

self.downloadButton.tintColor = [UIColor redColor];

See the example for more info.

GitHub


View Github

#ios #placeholder #swift #uibutton #uiprogressview
YOU MIGHT ALSO LIKE...
How to take action when a property changes

1. Taking Action When a Property Changes: Property Observers Swift lets you observe and respond to changes in a property’s ...

How to create your own structs? How to compute property values dynamically?

1. Creating Your Own Structs In Swift, a struct is a value type that you define with the struct keyword. ...

How to use trailing closures and shorthand syntax?

1. Trailing Closure Syntax When the last parameter to a function is a closure, you can write that closure after ...

How to create and use closures?

1. What Is a Closure (and Why Swift Loves Them) A closure in Swift is a self-contained block of functionality ...

How to provide default values for parameters How to handle errors in functions

1. Providing Default Values for Function Parameters (Deep Dive) 1.1 Syntax and Ordering Declaration You assign a default right in ...