Today, I have customized the progress bar in iOS and found that the system's progress bar height cannot be changed.
Now I have encapsulated a progress bar (actually uiview instead of Uiprogressview), can change the height of the progress bar, very useful, share to everyone, directly on the code:
CTWBProgress.h
Created by Wbapple on 16/7/31.
Copyright©2016 year Wang bin. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Ctwbprogress:uiview
progress bar background picture
@property (Retain, nonatomic) Uiimageview *trackview;
To fill a picture with a bar
@property (Retain, nonatomic) Uiimageview *progressview;
Progress
@property (nonatomic) cgfloat targetprogress;
Set the value of the progress bar
-(void) Setprogress: (cgfloat) Progress;
@end
Ctwbprogresss.m
Created by Wbapple on 16/7/31.
Copyright©2016 year Wang bin. All rights reserved.
#import "CTWBProgress.h"
@implementation ctwbprogress
Initialize the progress bar (here set the progress bar background picture and the into bar fill picture)
-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self)
{
Self.backgroundcolor = [Uicolor Clearcolor];
Background image
_trackview =
[[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, Frame.size.width, frame.size.height)];
[_trackview setimage:[uiimage imagenamed:@ "1.png"];
The main function of the current view is to cut out the out-of-bounds _progressview, so you need to set Clipstobounds to Yes
_trackview.clipstobounds = YES;
[Self addsubview:_trackview];
Fill image
_progressview = [[Uiimageview alloc]
Initwithframe:cgrectmake (0-frame.size.width, 0, Frame.size.width, frame.size.height)];
[_progressview setimage:[uiimage imagenamed:@ "2.png"];
[_trackview Addsubview:_progressview];
}
return self;
}
Set the value of the progress bar
-(void) Setprogress: (cgfloat) Progress
{
_targetprogress = progress;
[Self changeprogressviewframe];
}
Modify Display Content
-(void) changeprogressviewframe
{
_progressview.frame = CGRectMake (Self.frame.size.width * _targetprogress-self.frame.size.width,
0, Self.frame.size.width, self.frame.size.height);
}
@end
Using the progress bar method
#import "CTWBProgress.h"
Ctwbprogress* Progressview;
float Progressvlaue;
Give the progress bar a frame, set the value for the progress bar
Progressview = [[Ctwbprogress alloc] Initwithframe:cgrectmake (Fitwidth (108), Fitheight (960), Fitwidth (864), FITHEIGHT (80))];
[Progressview Setprogress:progressvlaue];
[Self.view Addsubview:progressview];
iOS Custom progress bar height (Implementation of Uiprogressview progress bar height change)