ios-battery Icon "Control battery display with Bezier curves"

Source: Internet
Author: User

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"

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.