The implementation results are as follows:
The interface is implemented with UITableView and Tabelviewcell, and the Red view is drawn with Uibezierpath. Note The red part of the upper left corner, the lower left corner is right angle yo!!!! Not much to say < here is really willing to use Uibezierpath to achieve!!!?? The code is as follows:
Controller code:
////VIEWCONTROLLER.M//Progressviewdemo////Created by think Peng on 2017/4/20.//Copyright 2017 think Peng. All rights reserved.//#import"ViewController.h"#import"ProgressTableViewCell.h"@interface Viewcontroller ()<uitableviewdelegate, uitableviewdatasource>@property (nonatomic, strong) UITableView*TableView, @property (nonatomic, strong) Cashapelayer*layer; @end @implementation Viewcontroller- (void) viewdidload {[Super viewdidload]; Self.navigationItem.title=@"Progressdemo"; [Self setui];}#pragmaMark-Setup Interface-(void) Setui {Self.tableview= [[UITableView alloc]initwithframe:cgrectmake (0,0, Self.view.frame.size.width, Self.view.frame.size.height) style:uitableviewstylegrouped]; Self.tableview.Delegate=Self ; Self.tableView.dataSource=Self ; Self.tableView.backgroundColor=[Uicolor Clearcolor]; //Register Cell[Self.tableview Registerclass:[progresstableviewcellclass] Forcellreuseidentifier:@"Cell"]; Self.tableView.tableFooterView=[[UIView alloc]init]; [Self.view AddSubview:self.tableView];}#pragmamark-uitableviewdatasource-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {return 1;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return 5;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Progresstableviewcell*cell = [TableView dequeuereusablecellwithidentifier:@"Cell"Forindexpath:indexpath]; returncell;}#pragmamark-uitableviewdelegate-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section {return 0.001f;;}-(CGFloat) TableView: (UITableView *) TableView heightforfooterinsection: (nsinteger) Section {return 0.0001f;}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {return -;} @end
Tabelviewcell Code:
////PROGRESSTABLEVIEWCELL.M//Progressviewdemo////Created by think Peng on 2017/4/21.//Copyright 2017 think Peng. All rights reserved.//#import"ProgressTableViewCell.h"#import"Masonry.h"#import"ProgressView.h"@interface Progresstableviewcell () @property (nonatomic, strong) UILabel*Titlelabel, @property (nonatomic, strong) Progressview*Progressview, @property (nonatomic, strong) UILabel*Numberlabel, @end @implementation Progresstableviewcell- (void) awakefromnib {[Super awakefromnib]; //Initialization Code}-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier {if(self =[Super Initwithstyle:style Reuseidentifier:reuseidentifier]) {[Self createsubviews]; [Self layOut]; } returnSelf ;}- (void) createsubviews {Self.titlelabel=[[UILabel alloc]init]; Self.titleLabel.font= [Uifont systemfontofsize: -]; Self.titleLabel.text=@"Xidan Grand Yue City"; Self.titleLabel.textAlignment=Nstextalignmentleft; [Self.contentview AddSubview:self.titleLabel]; Self.progressview=[[Progressview alloc]init]; Self.progressView.backgroundColor=[Uicolor Whitecolor]; Self.progressView.progress= Arc4random_uniform ( -) + +; [Self.contentview AddSubview:self.progressView]; Self.numberlabel=[[UILabel alloc]init]; Self.numberLabel.font= [Uifont systemfontofsize: -]; Self.numberLabel.text=@"¥2000"; Self.numberLabel.textAlignment=Nstextalignmentright; [Self.contentview AddSubview:self.numberLabel];}- (void) LayOut {[Self.titlelabel mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.mas_equalTo (Self.contentview). Offset (Ten); Make.centerY.mas_equalTo (Self.contentview);//Make.width.greaterThanOrEqualTo (@ ());Make.width.mas_equalTo (Self.contentView.frame.size.width *0.3); }]; [Self.progressview mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.mas_equalTo (self.titleLabel.mas_right). Offset (Ten); Make.height.mas_equalTo ( -); Make.centerY.mas_equalTo (Self.titleLabel.mas_centerY); Make.width.mas_equalTo (Self.contentView.frame.size.width*0.4); }]; [Self.numberlabel mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.mas_equalTo (self.progressView.mas_right). Offset (Ten); Make.centerY.mas_equalTo (Self.contentview); Make.right.mas_equalTo (Self.contentview). Offset (-Ten); }];} @end
Progressview Code:
////progressview.m//Progressviewdemo////Created by think Peng on 2017/4/20.//Copyright 2017 think Peng. All rights reserved.//#import"ProgressView.h"@interface Progressview () @end @implementation Progressview-(void) DrawRect: (cgrect) rect{//Create Bethel Path /*cgfloat width = self.progress/rect.size.width * rect.size.width; Displayed width = The total width of the value/setting returned by the server * full value; Displayed width = Full value * Scale value Scale value = Server returned width/full value*/cgfloat Width= Rect.size.width * Self.progress/Rect.size.width; //displayed width = The value returned by the server * The total width/full value of the set;Uibezierpath *path = [Uibezierpath bezierpathwithroundedrect:cgrectmake (0,0, width, rect.size.height) byroundingcorners:uirectcornertopright|uirectcornerbottomright Cornerradii:cgsizemake (Rect.size.height, rect.size.height)]; [[Uicolor Redcolor] setfill]; [path fill];}- (void) Setprogress: (cgfloat) progress{_progress=progress; //redraw, the system first creates the context associated with the view and then calls the DrawRect[self setneedsdisplay];} @end
is not super simple, but I did not think at first, or own too much food. ... Fight IT!!!
iOS uses Uibezierpath to implement Progressview