Giter VIP home page Giter VIP logo

downloadbutton's Introduction

DownloadButton

[![CI Status](http://img.shields.io/travis/Pavel Katunin/DownloadButton.svg?style=flat)](https://travis-ci.org/Pavel Katunin/DownloadButton) Version License Platform

Customizable appstore style download button.

Default button animation

Default button

Customizable designable components. Editing with IB.

Custom button animation

Custom button

Designable button

Usage

To run the example project, clone the repo, and run pod install from the Example directory first. Check example project to see usage.

#import <DownloadButton/PKDownloadButton.h>

Usage for representing network operations:

#pragma mark - PKDownloadButtonDelegate

- (void)downloadButtonTapped:(PKDownloadButton *)downloadButton 
                currentState:(PKDownloadButtonState)state {
    switch (state) {
        case kPKDownloadButtonState_StartDownload:
            self.downloadButton.state = kPKDownloadButtonState_Pending;
            [self.pendingSimulator startDownload];
        break;
        case kPKDownloadButtonState_Pending:
            [self.pendingSimulator cancelDownload];
            self.downloadButton.state = kPKDownloadButtonState_StartDownload;
        break;
            case kPKDownloadButtonState_Downloading:
            [self.downloaderSimulator cancelDownload];
            self.downloadButton.state = kPKDownloadButtonState_StartDownload;
        break;
        case kPKDownloadButtonState_Downloaded:
            self.downloadButton.state = kPKDownloadButtonState_StartDownload;
            self.imageView.hidden = YES;
        break;
        default:
            NSAssert(NO, @"unsupported state");
        break;
    }
}

#pragma mark - DownloaderSimulatorDelegate

- (void)simulator:(PKDownloaderSimulator *)simulator didUpdateProgress:(double)progress {
    if (simulator == self.pendingSimulator) {
        if (progress == 1.) {
            self.downloadButton.state = kPKDownloadButtonState_Downloading;
            [self.downloaderSimulator startDownload];
        }
    }
    else if (simulator == self.downloaderSimulator) {
        self.downloadButton.stopDownloadButton.progress = progress;
        if (progress == 1) {
            self.downloadButton.state = kPKDownloadButtonState_Downloaded;
            self.imageView.hidden = NO;
        }
    }
}

Appearance customization:

#import "UIImage+PKDownloadButton.h"
#import "UIButton+PKDownloadButton.h"

[self.downloadButton.downloadedButton cleanDefaultAppearance];
[self.downloadButton.downloadedButton setBackgroundImage:[UIImage buttonBackgroundWithColor:[UIColor redColor]]
forState:UIControlStateNormal];
[self.downloadButton.downloadedButton setBackgroundImage:[UIImage highlitedButtonBackgroundWithColor:[UIColor redColor]]
forState:UIControlStateHighlighted];
[self.downloadButton.downloadedButton setTitle:@"delete" forState:UIControlStateNormal];
[self.downloadButton.downloadedButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self.downloadButton.downloadedButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

self.downloadButton.stopDownloadButton.tintColor = [UIColor blackColor];
self.downloadButton.stopDownloadButton.filledLineStyleOuter = YES;

self.downloadButton.pendingView.tintColor = [UIColor orangeColor];
self.downloadButton.pendingView.radius = 24.f;
self.downloadButton.pendingView.emptyLineRadians = 2.f;
self.downloadButton.pendingView.spinTime = 3.f;

[self.downloadButton.startDownloadButton cleanDefaultAppearance];
[self.downloadButton.startDownloadButton setImage:[UIImage imageNamed:@"download_default"] forState:UIControlStateNormal];

Requirements

Requires iOS SDK version > 8.0

Installation

DownloadButton is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DownloadButton"

Author

Pavel Katunin, [email protected]

License

DownloadButton is available under the Apache License, Version 2.0. See the LICENSE file for more info.

downloadbutton's People

Contributors

dautermann avatar gavrix avatar markst avatar mmllr avatar mohamede1945 avatar onekiloparsec avatar pavelkatunin avatar ryanholden8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

downloadbutton's Issues

[feature] framework target and carthage support

The project lacks an actual framework target so that it can be linked dynamically to apps and app extensions. "CocoaPods only" distribution makes this code hard to use by developers whose dependencies are dynamic frameworks.

P.S. It will be possible to use this code with Carthage package manager

Support for iOS 7

Is there any reason support for iOS 7 can't be added? It would be helpful since the button changes were made back in 7 and continue in 8.

Crash when having a `nil` attributedTitle

Hi,

after I upgraded from 6866d4d to ff72143, my app started crashing. I discovered that it is due to me setting attributedTitle of the startDownloadButton to nil, and this code thus initializing an NSAttributedString with a nil string.

I think the solution is quite easy - in [PKDownloadButton updateButton:title:], check if the passed title is nil. If yes, initialize attrTitle itself as nil.

Updating DownloadButton in a cell while scrolling

Hi,

Thanks for this awesome component.
I have a situation where I have added a DownloadButton to each row of a UITableView. Imagine I tap on one of them and a download starts and the button gets updated when the download progresses. Now If I scroll, the cells get reused. How can I restore the state of each DownloadButton? (Showing download progress to be exact)

Requires iOS SDK version > 8.0

I have review the code in the Classes file.didn't seen any api is only for ios SDK version 8.0 or later.
can you tell me Requires iOS SDK version > 8.0.
PS:my app need support ios sdk version >=7.0.
thanks.

DownloadButton usage in Swift with UITableView

Just added DownloadButton to my project. Have to say, it is great. Thank you, Pavel, for this awesome soluton! But still there are some things, I'd like to ask:

  1. How can I access UIImage+PKDownloadButton in Swift? When I try customising the button as in the example (calling UIImage initialiser with method buttonBackgroundWithColor), that initialiser in unaccessible. (I add DownloadButton as accessoryView to my UITableViewCell in cellForRowAtIndex method)
  2. In UITableViewController class, when I implement PKDownloadButtonDelegate, downloadButtonTapped method is never called when I tap the button. (I have a button in each row of my tableView). How should I properly implement it?
  3. When I programmatically change the DownloadButton state to .Downloading and the circle comes out, how can this circle be moved to the right side of the button corner? (Now it is on the left side)
  4. Maybe this one is not about this library, but still, is it possible to implement AppStore-like cloud button with the same functions? For example, when I tap the button and the Downloading circle comes out?
  5. How can I localise DownloadButton?

Sorry for the very long text, but I think this would be useful for many beginnes, like me

Thank you in advance.

Can't seem to change the start download button title (SWIFT)

Hey,
So I added your button to my table view in IB and created an IB outlet but when I try changing the start download title in viewDidLoad, nothing happens at all.
downloadButton.startDownloadButton.setTitle("Hello", forState: .Normal)
downloadButton.startDownloadButton.titleLabel?.text = "GET"

How to change the size of stopDownloadButton

I use this lib in swift, and add some constraints for PKDownloadButton, but I find the side of stopDownloadButton is not changed.
Who knows some way to change the size of stopDownloadButton?

Thanks

Swift Example code ?

Could you add Swift Example Code ?
to make me understand how to use it in swift .

Thank you

Problem setting progress

Hi,

I m trying to set the progress to the stopDownloadButton in a NSURLSessionDownloadTask . I see the stopDownloadButton, but the progress is not increasing. Here is my block:

progress:^(NSProgress * _Nonnull downloadProgress) {
     self.downloadButton.stopDownloadButton.progress = downloadProgress.fractionCompleted;
}                                                                

What am I doing wrong?

Thanks in advance,

Compiling fails on Xcode 8

When I tried to compile it on Xcode 8, the compiling fails, and here is the error description:

CodeSign /Users/xxx/Library/Developer/Xcode/DerivedData/YYY-devhhrztnwiafzdnbmqgugeublld/Build/Products/Debug-iphonesimulator/DownloadButton.bundle
cd /Users/ydong/Documents/codebase/YYY/YYY/Pods
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Signing Identity: "-"

/usr/bin/codesign --force --sign - --timestamp=none /Users/xxx/Library/Developer/Xcode/DerivedData/YYY-devhhrztnwiafzdnbmqgugeublld/Build/Products/Debug-iphonesimulator/DownloadButton.bundle

/Users/xxx/Library/Developer/Xcode/DerivedData/YYY-devhhrztnwiafzdnbmqgugeublld/Build/Products/Debug-iphonesimulator/DownloadButton.bundle: bundle format unrecognized, invalid, or unsuitable
Command /usr/bin/codesign failed with exit code 1

Does anyone knows what's the going wrong?

Using DownloadButton will cause *all* UIButtons with a tintColor be shown with a border

In UIButton+PKDownloadButton.m, the -tintColorDidChange method is reimplemented. This replaced the default implementation of the said method, and makes all UIButtons without a custom -tintColorDidChange to gain the rounded border whenever their tintColor is changed.

It is better to create a UIButton subclass for the "startDownloadButton" and "downloadedButton" and override -tintColorDidChange in the subclass to avoid the global effect.

How to change empty line color

I find the default color of the empty line is gray, and I want to change it to red. and implement the following code.
self.btnDownload.stopDownloadButton.tintColor = UIColor.red

But it does not work, it only makes the filledLine color changed.

Who knows how to change the color of empty line?

constraint error

2018-05-28 20:04:20.696946+0800 DownloadButton_Example[22493:1707307] +[CATransaction synchronize] called within transaction
2018-05-28 20:04:21.066380+0800 DownloadButton_Example[22493:1707307] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60400028d4d0 PKCircleView:0x7fe842d1c7a0.width == 0 (active)>",
"<NSLayoutConstraint:0x60400028d750 H:|-(0)-[PKCircleView:0x7fe842d1c7a0] (active, names: '|':PKStopDownloadButton:0x7fe842d1b980 )>",
"<NSLayoutConstraint:0x60400028d7a0 H:[PKCircleView:0x7fe842d1c7a0]-(0)-| (active, names: '|':PKStopDownloadButton:0x7fe842d1b980 )>",
"<NSLayoutConstraint:0x60000028a5f0 PKDownloadButton:0x7fe842c0d800.width == 93 (active)>",
"<NSLayoutConstraint:0x60000028a730 H:|-(0)-[PKStopDownloadButton:0x7fe842d1b980] (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>",
"<NSLayoutConstraint:0x60000028a780 H:[PKStopDownloadButton:0x7fe842d1b980]-(0)-| (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028d4d0 PKCircleView:0x7fe842d1c7a0.width == 0 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-05-28 20:04:21.070967+0800 DownloadButton_Example[22493:1707307] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60400028d520 PKCircleView:0x7fe842d1c7a0.height == 0 (active)>",
"<NSLayoutConstraint:0x60400028d7f0 V:|-(0)-[PKCircleView:0x7fe842d1c7a0] (active, names: '|':PKStopDownloadButton:0x7fe842d1b980 )>",
"<NSLayoutConstraint:0x60400028d840 V:[PKCircleView:0x7fe842d1c7a0]-(0)-| (active, names: '|':PKStopDownloadButton:0x7fe842d1b980 )>",
"<NSLayoutConstraint:0x60000028a460 PKDownloadButton:0x7fe842c0d800.height == 30 (active)>",
"<NSLayoutConstraint:0x60000028a7d0 V:|-(0)-[PKStopDownloadButton:0x7fe842d1b980] (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>",
"<NSLayoutConstraint:0x60000028a820 V:[PKStopDownloadButton:0x7fe842d1b980]-(0)-| (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028d520 PKCircleView:0x7fe842d1c7a0.height == 0 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-05-28 20:04:21.072207+0800 DownloadButton_Example[22493:1707307] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60400028de30 PKCircleView:0x7fe842d20e40.width == 26 (active)>",
"<NSLayoutConstraint:0x60400028de80 H:|-(0)-[PKCircleView:0x7fe842d20e40] (active, names: '|':PKPendingView:0x7fe842d202e0 )>",
"<NSLayoutConstraint:0x600000289f60 H:[PKCircleView:0x7fe842d20e40]-(0)-| (active, names: '|':PKPendingView:0x7fe842d202e0 )>",
"<NSLayoutConstraint:0x60000028a5f0 PKDownloadButton:0x7fe842c0d800.width == 93 (active)>",
"<NSLayoutConstraint:0x60000028a9b0 H:|-(0)-[PKPendingView:0x7fe842d202e0] (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>",
"<NSLayoutConstraint:0x60000028aa00 H:[PKPendingView:0x7fe842d202e0]-(0)-| (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028de30 PKCircleView:0x7fe842d20e40.width == 26 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-05-28 20:04:21.073154+0800 DownloadButton_Example[22493:1707307] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60400028dde0 PKCircleView:0x7fe842d20e40.height == 26 (active)>",
"<NSLayoutConstraint:0x600000283a70 V:|-(0)-[PKCircleView:0x7fe842d20e40] (active, names: '|':PKPendingView:0x7fe842d202e0 )>",
"<NSLayoutConstraint:0x600000289a10 V:[PKCircleView:0x7fe842d20e40]-(0)-| (active, names: '|':PKPendingView:0x7fe842d202e0 )>",
"<NSLayoutConstraint:0x60000028a460 PKDownloadButton:0x7fe842c0d800.height == 30 (active)>",
"<NSLayoutConstraint:0x60000028aa50 V:|-(0)-[PKPendingView:0x7fe842d202e0] (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>",
"<NSLayoutConstraint:0x60000028aaa0 V:[PKPendingView:0x7fe842d202e0]-(0)-| (active, names: '|':PKDownloadButton:0x7fe842c0d800 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028dde0 PKCircleView:0x7fe842d20e40.height == 26 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Not able to see the progress

Hello,
I am not able to see the progress. I am just able to see the circle with stop button but no progress even though the app is downloading the content. I have manually added classes from the Download button folder under the Example app. Below is the relevant code:
if (self.progress.fractionCompleted > 0){
DLog(@"***** %f",self.progress.fractionCompleted);
self.downloadProgress.stopDownloadButton.progress = self.progress.fractionCompleted;
}

Pod spec only support 7.0

I think the podspec file is not set correctly. It targets iOS and 7.0 only. I think it should have the greater than or equal to 7.0 in the podspec so it can support all versions.

I currently get an error when trying to add it to my project.

[!] Unable to satisfy the following requirements:

  • 'DownloadButton' required by 'Podfile'

My Podfile targets 7.1 and up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.