iOS 实现进度条(progress)

#import <UIKit/UIKit.h>

@interface ZSDProgressView : UIView
{
    UIView *progressView;//进度view
}
//进度值
@property(nonatomic,assign)float progress;
@end
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#import "ZSDProgressView.h"
@implementation ZSDProgressView

-(id)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame])
    {
        self.backgroundColor=UIColorFromRGB(0xDADADA);
    }

    return self;
}
-(void)awakeFromNib
{

    self.backgroundColor=UIColorFromRGB(0xDADADA);
    progressView=[[UIView alloc]init];
    progressView.translatesAutoresizingMaskIntoConstraints=NO;
    [self addSubview:progressView];

}
-(void)setProgress:(float)progress
{
    _progress=progress;

    /**
     *  activePartView添加约束
     */

    //左边约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:progressView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];

     //上边约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:progressView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:0]];

    //高度约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:progressView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1 constant:self.frame.size.height]];

    //宽度约束
    NSLayoutConstraint *widthCon = [NSLayoutConstraint constraintWithItem:progressView
                                                                attribute:NSLayoutAttributeWidth
                                                                relatedBy:NSLayoutRelationEqual
                                                                   toItem:self
                                                                attribute:NSLayoutAttributeWidth
                                                               multiplier:_progress
                                                                 constant:0];
    [self addConstraint:widthCon];

    //用背景图来填充背景颜色
    UIImage *bgImage=[UIImage imageNamed:@"invest_jindu"];
    UIColor *bgColor=[UIColor colorWithPatternImage:bgImage];
    [progressView setBackgroundColor:bgColor];
    //更新约束
    [progressView needsUpdateConstraints];

}

@end
#import "ViewController.h"
#import "ZSDProgressView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet ZSDProgressView *progressView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)setBtnClick:(UIButton *)sender
{

    _progressView.progress=0.6;

}

@end

时间: 2024-07-30 13:24:55

iOS 实现进度条(progress)的相关文章

iOS自定义进度条高度(UIProgressView进度条高度改变的实现)

今天自定义了iOS中的进度条,发现系统的进度条高度无法改变, 现在自己封装了一种进度条(实际是是UIView而不是UIProgressView),可以改变进度条的高度,非常好用,分享给大家,直接上代码: //  CTWBProgress.h //  Created by WBapple on 16/7/31. //  Copyright © 2016年 王彬. All rights reserved. // #import <UIKit/UIKit.h> @interface CTWBProg

IOS 圆形进度条

// // CCProgressView.h // Demo // // Created by leao on 2017/8/7. // Copyright ? 2017年 zaodao. All rights reserved. // #import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, CCProgressViewStyle) { CCProgressViewStyleCircle, // 圆形进度条 CCProgressViewStyleB

iOS 渐变进度条

#import <UIKit/UIKit.h> @interface JianBianView : UIView //为了增加一个表示进度条的进行,可们可以使用mask属性来屏蔽一部分 @property (nonatomic, strong) CALayer *maskLayer; @property (nonatomic, assign) CGFloat progress; //动画方法 -(void)performAnimation; -(void)setProgress:(CGFloa

C# Windows 7任务栏开发之进度条(Progress Bar)

Windows 7 任务栏为我们增添了许多其他功能:Jump Lists,Window Preview,Progress Bar,Overlay Icon 等等. 新任务栏的功能使我们的操作更加方便快捷,微软提供了方便的工具Windows API Code Pack for .NET Framework 来帮助我们完成这些开发,程序中增加Microsoft.WindowsAPICodePack.dll 和Microsoft.WindowsAPICodePack.Shell.dll. 在使用IE

HTML5进度条progress的使用

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title> progress元素的使用</title> </head> <p id="pTip">开始下载</p> <progress value="0" max="100" id="proD

纯CSS3实现苹果iOS 7风格进度条

还记得iOS 7的“颠覆性”扁平化设计吗?其中的各种扁平化UI界面都让我们为之惊叹,其中的进度条更是让人喜欢 的不得了.今天就给大家分享一个用CSS3制作的iOS7进度条小教程,这是一款非常优秀的UI交互设计.下面就来看看演示效果以及实现方式吧! HTML结构代码 首先设计HTML的基本结构,大概如下: <div class="container"> <h1 class="text-center">iOS 7进度条</h1> &l

微信小程序组件解读和分析:六、progress进度条

progress进度条组件说明: 进度条,就是表示事情当前完成到什么地步了,可以让用户视觉上感知事情的执行.progress进度条是微信小程序的组件,和HTML5的进度条progress类似. progress进度条组件示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 1 2 3 4 5 <!--index.wxml--> <view class="content">     <text class="con-t

渐变颜色的进度条WGradientProgress-备用

今天我们来实现一个iOS平台上的进度条(progress bar or progress view).这种进度条比APPLE自带的更加漂亮,更加有“B格”.它拥有渐变的颜色,而且这种颜色是动态移动的,这里称之为WGradientProgress. 先来看看我们的目标长什么样子: WGradientProgress的使用方法很简单,主要有展示接口以及隐藏接口,目前显示的位置有两种选择: WProgressPosDown        //progress is on the down border

Bootstarp学习(十七)进度条

进度条 在网页中,进度条的效果并不少见,比如一个评分系统,比如加载状态等.就如下图所示的一个评分系统,他就是一个简单的进度条效果: 进度条和其他独立组件一样,开发者可以根据自己的需要,选择对应的版本: ? LESS版本:源码文件progress-bars.less ? Sass版本:源码文件_progress-bars.scss ? 编译后版本:bootstrap.css文件第4500行-第4575行 而且Bootstrap框架为大家提供多种样式风格的进度条,供大家使用(见右侧代码编辑器),这一