IOS-battery icon [control battery display with the beiser curve], ios-beiser
Based on the UIView class: WKJBatteryView
WKJBatteryView. h
#import <UIKit/UIKit.h>@interface WKJBatteryView : UIView/** value:0 - 100 */- (void)setBatteryValue:(NSInteger)value;@end
WKJBatteryView. m
# Import "WKJBatteryView. h "@ interface WKJBatteryView () // batterwidth @ property (nonatomic, assign) CGFloat B _width; // battery height @ property (nonatomic, assign) CGFloat B _height; // outside battery width @ property (nonatomic, assign) CGFloat B _lineW; @ property (nonatomic, strong) UIView * batteryView; @ end @ implementation threshold-(instancetype) initWithFrame :( CGRect) frame {self = [super initWithFrame: frame]; if (self) {[self drawBattery];} return self ;}// draw the icon-(void) drawBattery {// x coordinate CGFloat B _x = 1; // y coordinate CGFloat 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 labels: 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 a 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]; // 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.324 green: 0.941 blue: 0.413 alpha: 1.000]; [self addSubview: _ batteryView];} // control power display-(void) setBatteryValue :( NSInteger) value {if (value <10) {_ batteryView. backgroundColor = [UIColor redColor];} else {_ batteryView. backgroundColor = [UIColor colorWithRed: 0.324 green: 0.941 blue: 0.413 alpha: 1.000];} CGRect rect = _ batteryView. frame; rect. size. width = (value * (_ B _width-_ B _lineW * 2)/100; _ batteryView. frame = rect;} @ end