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. js 弹层 提示

    <!DOCTYPE html><html style="height: 100%;"><head lang="en"> &l ...

  2. 第一个python实例程序

    #!/usr/bin/python2.7 import os ls = os.linesep fname = raw_input("fname:"); while True: if ...

  3. sql server 2005导出数据

    */ EXEC sp_configure 'show advanced options', 1 GO */     配置选项 'show advanced options' 已从 0 更改为 1.请运 ...

  4. RedHat Enterprise Linux AS4&5 安装gcc过程

    三.Gcc安装方法(redhat 4): 一.安装步骤 1.使用which gcc命令查看gcc是否安装安装 2.如若没有安装则下载如下安装包,所需安装包如下 一共需要拷贝以下五个安装包: binut ...

  5. 手机端android/iPhone问题

    iPhone: 不能自动播放音乐, 去除默认样式 input:-webkit-appearance: none;border-radius:0px; video播放自动默认全屏解决-webkit-pl ...

  6. make -jN

    今天又一次尝试编译安卓,想测试一下编译的速度如何? 考虑机器是4核8线程,就用上了 make -j8,感觉上上速度是很快,刷屏就下来了,不过错误了,错误的提示大概是某个文件的规则没找到,想想了多线程并 ...

  7. tcp 的6个控制位

    原文:http://blog.chinaunix.net/uid-26413668-id-3376762.html TCP(Transmission Control Protocol) 传输控制协议 ...

  8. gnu make

    http://stackoverflow.com/questions/448910/makefile-variable-assignment 更加全面的介绍 http://blog.csdn.net/ ...

  9. android中设置ListView的选中的Item的背景颜色

    ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了,要实现放开鼠标后选择项的背景还是有颜色的. 1.配置main.xml <? ...

  10. input file图片上传预览

    两种方法,方法一: js代码: //头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $ ...