***

#import "HMBarView.h"
#import "UIColor+Random.h"
@implementation HMBarView - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
NSArray *data = @[@,@,@];
int count = data.count; CGFloat w = rect.size.width / ( * count - );
CGFloat h = ;
CGFloat x = ;
CGFloat y = ;
CGFloat viewH = rect.size.height;
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); for (int i = ; i < count; i++) {
h = viewH * [data[i] intValue] / 100.0;
x = * w * i;
y = viewH - h;
// 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, w, h)]; // 3.添加路径到上下文
CGContextAddPath(ctx, path.CGPath); [[UIColor randomColor] set]; // 4.渲染
CGContextFillPath(ctx);
} } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setNeedsDisplay];
} @end

IOS第16天(4,Quartz2D柱状图)的更多相关文章

  1. IOS第16天(5,Quartz2D雪花)

    *** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...

  2. IOS第16天(3,Quartz2D饼图)

    **** #import "HMPieView.h" #import "UIColor+Random.h" @implementation HMPieView ...

  3. IOS第16天(2,Quartz2D下载进度条)

    *************自定义下载的view的方法 #import "HMProgressView.h" @interface HMProgressView() @propert ...

  4. IOS第16天(1,Quartz2D基本图像绘制)

    ***************基本图像绘制 画线 #import "HMLineView.h" @implementation HMLineView - (id)initWithF ...

  5. iOS根据16进制的色号来设置颜色,适合封装工具类

    iOS中有时候UI给的一个色号就像 #54e1b7 这个,而我们一般设置颜色都是根据RBG来设置的,所以这里需要把这个16进制的色号转为RGB值,这里我们就使用一下的方法来调用设置颜色. + (UIC ...

  6. [Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability

    Concept: Truth, Information Flow, Clear Responsibilities and Immutability 1. Truth 1.1 Single Source ...

  7. [iOS]把16进制(#871f78)颜色转换UIColor

    // // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...

  8. 【转】iOS中16进制转10进制

    原文网址:http://www.voidcn.com/blog/u012198553/article/p-4976772.html /// 将十六进制的字符串转化为NSData - (NSData ) ...

  9. iOS UI进阶-1.0 Quartz2D

    概述 Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统.Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成PDF ...

随机推荐

  1. AOP动态代理解析4-jdk代理的实现

    JDKProxy的使用关键是创建自定义的InvocationHandler,而InvocationHandler中包含了需要覆盖的函数getProxy,而当前的方法正是完成了这个操作.在此确认一下JD ...

  2. Codeforces Round #375 (Div. 2) - A

    题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...

  3. Swift3.0语言教程获取C字符串

    Swift3.0语言教程获取C字符串 Swift3.0语言教程获取C字符串,为了让Swift和C语言可以实现很好的交互,开发者可以使用NSString的cString(using:)方法在指定编码格式 ...

  4. CSS3属性

    1.边框阴影(box-shadow ): 投影方式,X轴偏移,Y轴偏移,阴影模糊半径,阴影扩展半径,颜色 2.边框图像(border-image) 3.边框圆角:border-radius:5px 4 ...

  5. JS实现类似网页的测试考卷

    js实现table中获取不同td的值,并且md5加密,匹配md5的值(避免通过查看网页源代码可以看到正确答案),再用js前端判断输入与正确的值是否相同.最后再把错误的单词计数,并且输出,后端加入对应错 ...

  6. Spring MVC Test -Controller

    http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers- ...

  7. JQuery validate验证 自定义

    http://www.w3cschool.cc/jquery/jquery-plugin-validate.html http://blog.163.com/zhao_jinggui/blog/sta ...

  8. BZOJ3559 : [Ctsc2014]图的分割

    考试的时候看少了一行,导致暴力都写错额… 贾教说他出的这题水,但是我觉得并不水,那个结论还是很神的. 首先M(i)就是i的最小生成树的最大边, 设f[i]表示i属于哪个集合 我们把边按权值从小到大排序 ...

  9. [转]maven安装以及eclipse配置maven

    转自:http://jingyan.baidu.com/article/295430f136e8e00c7e0050b9.html 方法/步骤 下载maven的bin,在apache官方网站可以下载. ...

  10. 多表头固定demo--html Table

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...