DownloadButtoniOS 下载按钮

联合创作 · 2023-09-25 22:09

DownloadButton 是可自定义的 App Store 风格的下载按钮。可自定义设计组件,用 IB 进行编辑。
使用示例:

#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;
        }
    }
}

Designable button

浏览 5
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报