美文网首页
保存图片

保存图片

作者: iOS乐乐 | 来源:发表于2017-05-20 08:59 被阅读0次
    - (void)saveImage
    {
        int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width;
        UIImageView *currentImageView = _scrollView.subviews[index];
        
        UIImageWriteToSavedPhotosAlbum(currentImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
        
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] init];
        indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
        indicator.center = self.center;
        _indicatorView = indicator;
        [[UIApplication sharedApplication].keyWindow addSubview:indicator];
        [indicator startAnimating];
    }
    
    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
    {
        [_indicatorView removeFromSuperview];
        
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.backgroundColor = [UIColor colorWithRed:0.1f green:0.1f blue:0.1f alpha:0.90f];
        label.layer.cornerRadius = 5;
        label.clipsToBounds = YES;
        label.bounds = CGRectMake(0, 0, 150, 30);
        label.center = self.center;
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont boldSystemFontOfSize:17];
        [[UIApplication sharedApplication].keyWindow addSubview:label];
        [[UIApplication sharedApplication].keyWindow bringSubviewToFront:label];
        if (error) {
            label.text = SDPhotoBrowserSaveImageFailText;
        }   else {
            label.text = SDPhotoBrowserSaveImageSuccessText;
        }
        [label performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.0];
    }
    

    相关文章

      网友评论

          本文标题:保存图片

          本文链接:https://www.haomeiwen.com/subject/brguxxtx.html