1、在DrawLine.h文件中提供了一个改变电池电量数值的接口

//

//  DrawLine.h

//  Demo-draw2

//

//  Created by yyt on 16/5/11.

//  Copyright © 2016年 yyt. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface DrawLine : UIView

@property(nonatomic,assign) NSInteger currentNum;

@end

  2、在DrawLine.m文件中

//

//  DrawLine.m

//  Demo-draw2

//

//  Created by yyt on 16/5/11.

//  Copyright © 2016年 yyt. All rights reserved.

//

#import "DrawLine.h"

@implementation DrawLine

- (void)drawRect:(CGRect)rect {

CGContextRef bgContextRef = UIGraphicsGetCurrentContext();

CGRect frame = CGRectMake(10, 10, 40, 20);

CGContextAddRect(bgContextRef, frame);

CGContextSetLineWidth(bgContextRef, 2);

[commonBgColor setStroke];

CGContextStrokePath(bgContextRef);

CGContextMoveToPoint(bgContextRef, 50, 20);

CGContextAddLineToPoint(bgContextRef, 54, 20);

CGContextSetLineWidth(bgContextRef, 6);

CGContextStrokePath(bgContextRef);

CGContextMoveToPoint(bgContextRef, 10, 20);

CGContextAddLineToPoint(bgContextRef, 10+_currentNum*40/100, 20);

CGContextSetLineWidth(bgContextRef, 20);

CGContextStrokePath(bgContextRef);

}

@end

  3、在需要用的地方ViewController.m文件中

  我这里是写了个死数据,真正做项目的话,就需要在电量值发生改变的时候,修改currentNum值,然后setNeedsDisplay一下。

//

//  ViewController.m

//  Demo-draw2

//

//  Created by yyt on 16/5/11.

//  Copyright © 2016年 yyt. All rights reserved.

//

#import "ViewController.h"

#import "DrawLine.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor lightGrayColor];

DrawLine *lineView = [[DrawLine alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];

lineView.backgroundColor = [UIColor whiteColor];

  lineView.currentNum = 87;

[self.view addSubview:lineView];

}

@end

iOS开发——绘图电池按百分比显示的更多相关文章

  1. iOS开发(1) WebView和HTML 显示

    iOS 7 已经release了.现在学习iOS开发还是非常热门的.到处也有些团队在寻找iOS开发的人才. 那么,iOS开发.....省略了1万字.... HTML5 +CSS3+JS...再省略1万 ...

  2. iOS开发--绘图教程

    本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,翻译版本中加入了一些书中未涉及到的内容.希望本文能够对你有所帮助. 本文由海水的味道翻译整理,转载请 ...

  3. iOS开发 绘图详解

    Quartz概述 Quartz是Mac OS X的Darwin核心之上的绘图层,有时候也认为是CoreGraphics.共有两种部分组成   Quartz Compositor,合成视窗系统,管理和合 ...

  4. iOS开发遇到的错误 -- Label显示多行文字导致宽度和高度的问题

    Label的宽度问题 注意:UILabel下面需要设置preferredMaxLayoutWidth ,设置了autolayout和numberofline的UIlabel才显示多行 label宽度的 ...

  5. iOS开发之应用首次启动显示用户引导

    这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面  基本上都是使用UIScrollView 来实现, 新建一个继承于UIViewController ...

  6. [iOS 开发]UITableView第一行显示不完全

    造成这个问题的原因可能有两个: 1. UITableView的contentOffset属性的改变: 2. MJRefresh调用两次headerEndRefreshing会造成刷新后UITableV ...

  7. IOS开发之无法选择模拟器显示NO Scheme

    1. 不是 文件冲突的 看这个链接https://blog.csdn.net/sanpintian/article/details/7377365 2.文件冲突的  打开工程文件. 打开 直接 搜索 ...

  8. iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色

    btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...

  9. ios开发之--系统控件显示中文

    虽然一直知道X-code肯定提供有语言本地化的设置地方,但是一直也做个记录,有些时候的汉化,还是需要使用代码去控制,键盘的右下角.navagiton的return使用代码修改,调用系统相机时,也是出现 ...

随机推荐

  1. Coupons and Discounts

    Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. Hibernate 系列教程13-继承-鉴别器与内连接相结合

    Employee public class Employee { private Long id; private String name; HourlyEmployee public class H ...

  3. Learning Java 8 Syntax (Java in a Nutshell 6th)

    Java is using Unicode set Java is case sensitive Comments, C/C++ style abstract, const, final, int, ...

  4. [转]慎用InputStream的read()方法

    InputStream 此抽象类是表示字节输入流的所有类的超类. 我们从输入流中读取数据最常用的方法基本上就是如下 3 个 read() 方法了: 1 . read () 方法,这个方法 从输入流中读 ...

  5. css 8.1

    1. border-collapse 属性设置是否将表格边框折叠为单一边框: table { border-collapse:collapse;  } 如果没有规定 !DOCTYPE,border-c ...

  6. CodeForces--TechnoCup--2016.10.15--ProblemB--Bill Total Value(字符串处理)

    Bill Total Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. hdu1426 Sudoku Killer

    Sudoku Killer Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  8. POJ 1523 SPF (去掉割点能形成联通块的个数)

    思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...

  9. 转:JMeter--使用代理录制Web性.能测试脚.本

    Apache JMeter是一款纯Java的应用程序,用于对软件或系统做性.能测试,如压力测试.负载测试.最初设计是用于web应用测试,由于开源其测试组件不断被扩充,逐步扩展到其他测试领域中. 接下给 ...

  10. zf-表单填写以及相关业务流程

    这里是表单设置的地方 这是字段信息,如果设置了共享申请人名称的话 那么登记办件时,输入的申请人信息,会自动写入到这个字段中 还有这种,没设置共享的,那么就是申请后,自己输入信息即可 现在我们去申请办件 ...