如何在iOS设备上绘制波浪线 [英] How to draw wavy line on iOS device
本文介绍了如何在iOS设备上绘制波浪线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多点构造一条线。
I have many points constructing a line. How can I draw a wavy line through those points?
推荐答案
在iOS上使用CGContextRef。
Use CGContextRef on iOS.
WavyView.h
WavyView.h
#import <UIKit/UIKit.h>
@interface WavyView : UIView {
}
@end
WavyView.m
WavyView.m
#import "WavyView.h"
@implementation WavyView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 100, 100);
CGContextAddCurveToPoint(context,125,150,175,150,200,100);
CGContextAddCurveToPoint(context,225,50,275,75,300,200);
CGContextStrokePath(context);
}
- (void)dealloc {
[super dealloc];
}
@end
结果:
这篇关于如何在iOS设备上绘制波浪线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文