波形图
来源:互联网 发布:宁波邦元单片机 编辑:程序博客网 时间:2024/05/01 08:00
#import "Wave.h"
static BOOL layer =YES;
@interface Wave()
@property UIBezierPath* aPath;
@property CAShapeLayer *pathLayer;
@end
static NSInteger numhorizontal;
static NSUInteger numVertical;
@implementation Wave
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [superinitWithFrame:frame]) {
self.backgroundColor = [UIColorwhiteColor];
self.width =frame.size.width;
self.height = frame.size.height;
_pointArray = [NSMutableArrayarray];
self.aPath = [UIBezierPathbezierPath];
self.pathLayer = [CAShapeLayerlayer];
numhorizontal =8;
numVertical = 6;
}
return self;
}
/**
* 画背景
*/
-(void)drawBackground{
float horizontalSpacing = self.height/numhorizontal;
float verticalSpacing = self.width/numVertical;
CGContextRef context =UIGraphicsGetCurrentContext();
for (int a=0; a<=numhorizontal; a++) {
if (a==numhorizontal/2) {
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0., a*horizontalSpacing);
CGContextAddLineToPoint(context, self.width, a*horizontalSpacing);
// CGContextSetRGBStrokeColor(currentContext,
// 192/255.0, 192/255.0,192/255.0, 1.0);
[[UIColor redColor] set];
CGContextStrokePath(context);
}else{
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0., a*horizontalSpacing);
CGContextAddLineToPoint(context, self.width, a*horizontalSpacing);
// CGContextSetRGBStrokeColor(currentContext,
// 192/255.0, 192/255.0,192/255.0, 1.0);
[[UIColor grayColor] set];
CGContextStrokePath(context);
}
}
for (int a=0; a<=numVertical; a++) {
CGContextBeginPath(context);
CGContextMoveToPoint(context, a*verticalSpacing,0);
CGContextAddLineToPoint(context,a*verticalSpacing,self.height);
// CGContextSetRGBStrokeColor(currentContext,
// 192/255.0, 192/255.0,192/255.0, 1.0);
[[UIColor grayColor] set];
CGContextStrokePath(context);
}
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
[selfdrawBackground];
// UIColor *color = [UIColor redColor];
// [color set]; //设置线条颜色
// UIBezierPath* aPath = [UIBezierPath bezierPath];
// aPath.lineWidth = 5.0;
//
// aPath.lineCapStyle = kCGLineCapRound; //线条拐角
// aPath.lineJoinStyle = kCGLineCapRound; //终点处理
//
// // Set the starting point of the shape.
// [aPath moveToPoint:CGPointMake(100.0, 0.0)];
//
// // Draw the lines
// [aPath addLineToPoint:CGPointMake(200.0, 40.0)];
// [aPath addLineToPoint:CGPointMake(160, 140)];
// [aPath addLineToPoint:CGPointMake(40.0, 140)];
// [aPath addLineToPoint:CGPointMake(0.0, 40.0)];
// [aPath closePath]; //第五条线通过调用closePath方法得到的
//
// [aPath stroke]; //Draws line 根据坐标点连线
UIColor *color = [UIColorgrayColor];
[color set]; //设置线条颜色
[self.aPathremoveAllPoints];
self.aPath.lineWidth =1;
self.aPath.lineCapStyle = kCGLineCapRound; //线条拐角
self.aPath.lineJoinStyle = kCGLineCapRound; //终点处理
float num = self.width/10;
int ponit = num/3;
float cont = 0.0;
for (int a=0; a<=10; a++) {
cont = (a+1)*num;
int ard = arc4random()%50+200;
int are = arc4random()%50+200;
[self.aPathmoveToPoint:CGPointMake(a*num,self.height/2)];
[self.aPathaddCurveToPoint:CGPointMake(cont,self.height/2)controlPoint1:CGPointMake(cont-2*ponit,self.height/2-ard)controlPoint2:CGPointMake(cont-ponit,self.height/2+are)];
// [aPath stroke];
}
self.pathLayer.frame =self.bounds;
self.pathLayer.path =self.aPath.CGPath;
self.pathLayer.strokeColor = [[UIColorgrayColor] CGColor];
self.pathLayer.fillColor =nil;
self.pathLayer.lineWidth =1.0f;
self.pathLayer.lineJoin =kCALineJoinBevel;
[self.layeraddSublayer:self.pathLayer];
CABasicAnimation *pathAnimation = [CABasicAnimationanimationWithKeyPath:@"strokeEnd"];
pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 2.0;
pathAnimation.fromValue = [NSNumbernumberWithFloat:0.0f];
pathAnimation.toValue = [NSNumbernumberWithFloat:1.0f];
[self.pathLayeraddAnimation:pathAnimation forKey:@"strokeEnd"];
}
- 波形图
- 方波波形图
- 绘制wav波形图
- 2. 绘制波形图
- Qt波形图
- canvas画波形图
- java绘制波形图
- android 音乐波形图
- qt-画波形图
- android 波形图
- qt 波形图
- android 波形图
- 状态波形图控件
- AVAssetReader 音频波形图
- 关于LabVIEW的波形图与波形图表
- java绘制音频波形图
- android音频波形图绘制
- 播放录音文件波形图
- jquery1.8.3升级到2.1.4遇到的几个问题
- [Linux]Shell的运算符和特殊变量
- 支持visual studio 2013的操作系统
- java实现字符串逆向输出(续)
- 电子商务行业数据集成案例介绍
- 波形图
- sql基本查询———增量
- 信号量 Linux函数 semget();semctl();semop();
- The given node was not created by the current document
- 盘点8种CSS实现垂直居中水平居中的绝对定位居中技术
- myeclipse自动关闭问题
- Vim整合AStyle进行代码美化
- 第1章第2节练习题10 查找指定倒数结点
- fragment调用方法isadded()、isvisible()