iOS Custom progress bar height (Implementation of Uiprogressview progress bar height change)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.