自定义类似 App Store 的下载按钮:DownloadButton

DownloadButton   2015-06-04 15:29:38 发布
您的评价:
     
0.0
收藏     0收藏
文件夹
标签
(多个标签用逗号分隔)
DownloadButton, 自定义类似 App Store 的下载按钮。

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 runpod installfrom 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];

项目主页:http://www.open-open.com/lib/view/home/1433388079166

扩展阅读

iOS 下载按钮:DownloadButton
类似于 App store 中 app 的滑动行为:AppStoreStyleHorizontalScrollView
运用 Ext JS 4 的 MVC 架构
GitHub 优秀的 Android 开源项目
8 款 App 全面提升你的 Mac OS X 鼠标体验

为您推荐

小笨狼的LLDB技巧:chisel
iOS验证码倒计时按钮
AngularJS的增删改查、state嵌套案例,不涉及服务端
iOS-图片拉伸技巧
Xcode7 插件开发:从开发到pull到Alcatraz

更多

DownloadButton
iOS开发
相关文档  — 更多
相关经验  — 更多
相关讨论  — 更多