Based on UIView class: Wkjbatteryview
WKJBatteryView.h
#import <UIKit/UIKit.h>@interface wkjbatteryview:uiview/* */-(void) Setbatteryvalue: (nsinteger) value; @end
wkjbatteryview.m
#import "WKJBatteryView.h"@interfaceWkjbatteryview ()///Battery Width@property (nonatomic,assign) cgfloat b_width;///Battery Height@property (nonatomic,assign) cgfloat b_height;///wide external line of battery@property (nonatomic,assign) cgfloat b_linew; @property (nonatomic,strong) UIView*Batteryview;@end@implementationWkjbatteryview-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {[self drawbattery]; } returnSelf ;}///Picture icon- (void) drawbattery{///x-coordinateCGFloat b_x =1; ///y-coordinateCGFloat b_y =1; _b_height= Self.bounds.size.height-2; _b_width= Self.bounds.size.width-5; _b_linew=1; //draw the battery "left battery"Uibezierpath *pathleft = [Uibezierpath bezierpathwithroundedrect:cgrectmake (b_x, b_y, _b_width, _b_height) Cornerradius:2]; Cashapelayer*batterylayer =[Cashapelayer layer]; Batterylayer.linewidth=_b_linew; Batterylayer.strokecolor=[Uicolor Lightgraycolor]. Cgcolor; Batterylayer.fillcolor=[Uicolor Clearcolor]. Cgcolor; Batterylayer.path=[Pathleft Cgpath]; [Self.layer Addsublayer:batterylayer]; //Draw Battery "right battery Arrow"Uibezierpath *pathright =[Uibezierpath Bezierpath]; [Pathright movetopoint:cgpointmake (b_x+ _b_width+1, B_y + _b_height/3)]; [Pathright addlinetopoint:cgpointmake (b_x+ _b_width+1, B_y + _b_height *2/3)]; Cashapelayer*layerright =[Cashapelayer layer]; Layerright.linewidth=2; Layerright.strokecolor=[Uicolor Lightgraycolor]. Cgcolor; Layerright.fillcolor=[Uicolor Clearcolor]. Cgcolor; Layerright.path=[Pathright Cgpath]; [Self.layer Addsublayer:layerright]; ///in-Battery filling_batteryview = [[UIView alloc]initwithframe:cgrectmake (b_x +1, B_y + _b_linew,0, _b_height-_b_linew *2)]; _batteryview.layer.cornerradius=2; _batteryview.backgroundcolor= [Uicolor colorwithred:0.324Green0.941Blue0.413Alpha1.000]; [Self Addsubview:_batteryview];}///Control Battery Display- (void) Setbatteryvalue: (Nsinteger) value{if(value<Ten) {_batteryview.backgroundcolor=[Uicolor Redcolor]; }Else{_batteryview.backgroundcolor= [Uicolor colorwithred:0.324Green0.941Blue0.413Alpha1.000]; } cgrect rect=_batteryview.frame; Rect.size.width= (value* (_b_width-_b_linew *2))/ -; _batteryview.frame=rect;}@end
ios-battery Icon "Control battery display with Bezier curves"