设为首页 加入收藏

TOP

功能源代码(扇形进度)及Delegate运用在开放事件中、UINavigationController的封装(一)
2017-10-13 10:23:54 】 浏览:8331
Tags:功能 源代码 扇形 进度 Delegate 运用 开放 事件 UINavigationController 封装

1:扇形进度视图及运用

首先先创建扇形的视图,传入进度值

#import <UIKit/UIKit.h>

@interface LHProgressView : UIView

@property (nonatomic) float progress;

@end
#import "LHProgressView.h"
#define MinProgress (1.0 / 16.0)

@implementation LHProgressView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        _progress = MinProgress;
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextFillPath(context);
    CGRect aRect= CGRectMake(2, 2, self.bounds.size.width - 4, self.bounds.size.height - 4);
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.9);
    CGContextSetLineWidth(context, 2.0);
    CGContextAddEllipseInRect(context, aRect);
    CGContextDrawPath(context, kCGPathStroke);
    
    CGFloat centerX = self.bounds.size.width / 2;
    CGFloat centerY = self.bounds.size.height / 2;
    
    UIColor *aColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.9];
    CGContextSetFillColorWithColor(context, aColor.CGColor);
    CGContextSetLineWidth(context, 0.0);
    CGContextMoveToPoint(context, centerX, centerY);
    CGContextAddArc(context, centerX, centerY, (self.bounds.size.width - 10) / 2,  - M_PI_2, - M_PI_2 + self.progress * 2 *M_PI, 0);
    CGContextClosePath(context);
    CGContextDrawPath(context, kCGPathFillStroke);

}

- (void)setProgress:(float)progress
{
    _progress = progress;
    
    if (_progress < MinProgress) {
        _progress = MinProgress;
    }
    
    if (_progress >= 1.0) {
        
        [self setNeedsDisplay];
        [self removeFromSuperview];
        
    } else {
        
        [self setNeedsDisplay];
        
    }
    
}

@end

运用:

@property(nonatomic, strong)LHProgressView *progressView;
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor clearColor];
        
        _progressView = [[LHProgressView alloc] init];
        
    }
    
    return self;
}
- (void)setItemImageUrl:(NSString *)itemImageUrl
{
    _itemImageUrl = itemImageUrl;
    
    BOOL imageExist = [[SDWebImageManager sharedManager] cachedImageExistsForURL:[NSURL URLWithString:itemImageUrl]];
    
    if (_itemImageProgress == 1.0 || imageExist) {
        
        [_progressView removeFromSuperview];
        
    } else {
        
        _progressView.bounds = CGRectMake(0, 0, 50, 50);
        _progressView.center = CGPointMake((self.bounds.size.width) / 2, (self.bounds.size.height) / 2);
        [self addSubview:_progressView];
        
        _progressView.progress = _itemImageProgress;
        
    }
    
    _itemImageView.image = _itemImage;
    
    [self resetSize];
    
    __weak LHProgressView *progressView = _progressView;
    __weak LHPhotoView *photoView = self;
    NSInteger index = self.tag - 1;
    
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:itemImageUrl] options:SDWebImageRetryFailed | SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
        if ([photoView.photoViewDelegate respondsToSelector:@selector(photoIsShowingPhotoViewAtIndex:)]) {
            BOOL isShow = [photoView.photoViewDelegate photoIsShowingPhotoViewAtIndex:index];
            
            if (isShow) {
                if (receivedSize > kMinProgress) {
                    progressView.progress = (float)receivedSize/expectedSize;
                }
            }
            
        }
        
        if ([photoView.photoViewDelegat
首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇OC 类别与扩展(匿名类别) 下一篇完全定制UITabBarViewController

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目