# [翻译] MCProgressView 使用自定义图片做进度显示

+关注继续查看

MCProgressView 使用自定义图片做进度显示

https://github.com/Baglan/MCProgressView

Progress bar view with custom images.

## Installation（安装）

2. Copy files from the 'Classes' folder into your project.将‘Classes’文件夹拷贝到你的工程当中

## Usage（使用）

You will first need to create custom images for background and foreground or copy the ones coming with this project to your project.

#import "MCProgressBarView.h"


Initialize the images:

UIImage * backgroundImage = [[UIImage imageNamed:@"progress-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
UIImage * foregroundImage = [[UIImage imageNamed:@"progress-fg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];


Notice the [UIImage -resizableImageWithCapInsets:] call. You can read more about it in the documnetation for this method. Essentiually, it defines which parts of the image will not be stretched when image is resized. Here, it's used to mark the left and the right edges.

Create the view and add it to the view hierarchy:

MCProgressBarView * _progressBarView = [[MCProgressBarView alloc] initWithFrame:CGRectMake(25, 100, 270, 20)
backgroundImage:backgroundImage
foregroundImage:foregroundImage];



Now, the progress you set (in the range of 0.0 to 1.0), will be reflected in the component:

_progressBarView.progress = 0.25;


### offsetForZero（0处的偏移量）

Matt Curtis pointed out that when progress is 0.0, there is still some initial progress indicator shown (see the image above). After some consideration, I've decided that there are situations when that is desirable and some situations when no progress should be shown. To address this, a new property has been added:

Matt Curtis 指出，当进度为0.0时，还是有一些进度显示出来了（看上面的图片）。之后我决定，某些特定的情况下不显示进度条而有时候显示，为了标志这个，我添加了一个新的属性：

@property (nonatomic, assign) CGFloat offsetForZero;


The default value of this property is the sum of the left and the right cap inset for the foreground image. To "taper off" the initial size of the progress indicator, you can set it to a lower value. For the images in the sample project, that value can be set to 10.0:

progressBarView.offsetForZero = 10.0;


See the sample image above to see the effect. That value can vary depending on the images you use in your project.

CircleImageView 圆形图片头像实现
package com.view.drop; import android.content.Context; import android.content.res.TypedArray; import android.
749 0
JS导出PDF插件（支持中文、图片使用路径）

1755 0
android自定义view实现progressbar的效果

1402 0
Swift基础－－使用TableViewController自定义列表
941 0
+关注
711

0

《2021云上架构与运维峰会演讲合集》

《零基础CSS入门教程》

《零基础HTML入门教程》