iOS开发——绘图电池按百分比显示
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开发——绘图电池按百分比显示的更多相关文章
- iOS开发(1) WebView和HTML 显示
iOS 7 已经release了.现在学习iOS开发还是非常热门的.到处也有些团队在寻找iOS开发的人才. 那么,iOS开发.....省略了1万字.... HTML5 +CSS3+JS...再省略1万 ...
- iOS开发--绘图教程
本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,翻译版本中加入了一些书中未涉及到的内容.希望本文能够对你有所帮助. 本文由海水的味道翻译整理,转载请 ...
- iOS开发 绘图详解
Quartz概述 Quartz是Mac OS X的Darwin核心之上的绘图层,有时候也认为是CoreGraphics.共有两种部分组成 Quartz Compositor,合成视窗系统,管理和合 ...
- iOS开发遇到的错误 -- Label显示多行文字导致宽度和高度的问题
Label的宽度问题 注意:UILabel下面需要设置preferredMaxLayoutWidth ,设置了autolayout和numberofline的UIlabel才显示多行 label宽度的 ...
- iOS开发之应用首次启动显示用户引导
这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面 基本上都是使用UIScrollView 来实现, 新建一个继承于UIViewController ...
- [iOS 开发]UITableView第一行显示不完全
造成这个问题的原因可能有两个: 1. UITableView的contentOffset属性的改变: 2. MJRefresh调用两次headerEndRefreshing会造成刷新后UITableV ...
- IOS开发之无法选择模拟器显示NO Scheme
1. 不是 文件冲突的 看这个链接https://blog.csdn.net/sanpintian/article/details/7377365 2.文件冲突的 打开工程文件. 打开 直接 搜索 ...
- iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色
btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...
- ios开发之--系统控件显示中文
虽然一直知道X-code肯定提供有语言本地化的设置地方,但是一直也做个记录,有些时候的汉化,还是需要使用代码去控制,键盘的右下角.navagiton的return使用代码修改,调用系统相机时,也是出现 ...
随机推荐
- java基础增强
Eclipse使用: java Compile配置的是java编译环境 java Build path配置的是java运行环境 运行环境的版本必须高于编译环境的版本.否则报错 工程上 右键--prop ...
- 字符串编码问题(Ascii、Unicode、UCS-2、GBK、UTF-8)
1.字符编码的发展 第一阶段:ASCII阶段,(American Standard Code for Information Interchange, "美国信息交换标准码),计算机当时只支 ...
- linux视频学习(简单介绍)20160405
看一周学会linux系统的学习笔记. 1.linux系统是一个安全性高的开源,免费的多用户多任务的操作系统. 2.linux工作分为linux系统管理员,linux程序员(PC上软件开发,嵌入式开发) ...
- asm: Writing Inline Assembly
A usual IA includes these parts: asm [volatile] ( AssemblerTemplate : OutputOperands [ : InputOperan ...
- GDB: basics
Before Debugging, generating the debugging info using gcc -g3 *.c/cpp; then gdb ~.out/exe using comm ...
- stdafx文件介绍
MSDN介绍: These files are used to build a precompiled header file Projname.pch and a precompiled types ...
- Debian 安装 vmware-tools 手记
debian 8.5 源 deb http://ftp.de.debian.org/debian jessie main http://mirrors.163.com/.help/debian.htm ...
- UVALive 4031 Integer Transmission(贪心 + DP)
分析:求出最大值和最小值比较简单,使用贪心法,求最小值的时候我们让所有的0尽可能的向后延迟就可以了,求最大值则相反. 关键在于求出可以组合出的数字个数. 这就是组合数学版的dp了,我们让dp[i][j ...
- MYSQL数据库的套接字文件,pid文件,表结构文件
socket文件:当用Unix域套接字方式进行连接时需要的文件. pid文件:MySQL实例的进程ID文件. MySQL表结构文件:用来存放MySQL表结构定义文件. 套接字文件 Unix系统下本地连 ...
- 在linux下用tomcat部署java web项目的过程与注意事项
在linux下用tomcat部署java web项目的过程与注意事项 一.安装JDK 到http://www.oracle.com/technetwork/java/javase/downloads/ ...