列表progress动画

本文介绍如何创建一个自定义的UI组件FLGProgressView,该组件用于列表中显示带有动画效果的百分比进度条。通过设置不同的比例值,实现不同单元格内进度条的动态展示。在tableView的cellForRowAtIndexPath方法中调用,根据条件设置不同的进度值,以实现动画效果。
摘要由CSDN通过智能技术生成

 

不知道怎么描述,就是列表里有百分比的条,单个出现时要有个动画

 

 

创建FLGProgressView 继承UIView

FLGProgressView.h

 

 

@interface FLGProgressView : UIView

 

@property (nonatomic, strong) UIView *frontView;///

@property (nonatomic, strong) UIView *backView;

- (void)setpro:(CGFloat)pro;

 

@end

FLGProgressView.m

 

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];

    if (self) {

        [self createView];

    }

    return self;

}

- (void)createView{

    [self addSubview:self.backView];

    self.backView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);

    ///

    [self addSubview:self.frontView];

    self.frontView.frame = CGRectMake(0, 0, 0, self.frame.size.height);

}

- (UIView *)frontView{

    if (!_frontView) {

        _frontView = [[UIView alloc] init];

        _frontView.backgroundColor = [UIColor orangeColor];

    }

    return _frontView;

}

- (UIView *)backView{

    if (!_backView) {

        _backView = [[UIView alloc] init];

        _backView.backgroundColor = [UIColor lightGrayColor];

    }

    return _backView;

}

- (void)setpro:(CGFloat)pro{

     self.frontView.frame = CGRectMake(0, 0, 0, self.frame.size.height);

    [UIView animateWithDuration:1 animations:^{

        self.frontView.frame = CGRectMake(0, 0, self.frame.size.width*pro, self.frame.size.height);

    }];

}

 

 

 

controller.m tableviewcell 协议方法里

 

 

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *reuse = @"reuse";

    TablehaViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];

    if (!cell) {

        cell = [[TablehaViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];

    }

    if (indexPath.row%2==0) {

        [cell reloadCell:0.4];

    }else{

        [cell reloadCell:0.8];

    }

    return cell;

}

 

TablehaViewCell.m

 

创建progress

 

 self.progress = [[FLGProgressView alloc] initWithFrame:CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width-20, 10)];

    [self.contentView addSubview:self.progress];

 

 

 

给progress 赋值 Pro是个0-1的小数

 

- (void)reloadCell:(CGFloat)pro{

 

    [self.progress setpro:pro];

    

}

 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值