贝塞尔曲线 UIBezierPath
来源:互联网 发布:java开源b2b商城系统 编辑:程序博客网 时间:2024/05/30 23:46
#import "BezierPathView.h"
#define kDegreesToRadians(degrees) ((pi * degrees) / 180)
@implementation BezierPathView
- (void)drawRect:(CGRect)rect {
// 画三角形
[selfdrawTrianglePath];
// 画矩形
[selfdrawRectPath];
// 画圆
[selfdrawCiclePath];
// 画带圆角的矩形
[selfdrawRoundedRectPath];
// 画弧
[selfdrawARCPath];
// 画二次贝塞尔曲线
[selfdrawSecondBezierPath];
// 画三次贝塞尔曲线
[selfdrawThirdBezierPath];
}
- (void)drawTrianglePath
{
UIBezierPath *path = [UIBezierPathbezierPath];
[path moveToPoint:CGPointMake(20,20)];
[path addLineToPoint:CGPointMake(60,20)];
[path addLineToPoint:CGPointMake(40,40)];
[path closePath];
// 设置线宽
path.lineWidth =1.5;
// 设置填充颜色
UIColor *fillColor = [UIColorgreenColor];
[fillColor set];
[path fill];
// 设置画笔颜色
UIColor *strokeColor = [UIColorblueColor];
[strokeColor set];
// 根据我们设置的各个点连线
[path stroke];
}
- (void)drawRectPath
{
UIBezierPath *path = [UIBezierPathbezierPathWithRect:CGRectMake(100,20, 100, 50)];
path.lineWidth =1.5;
/*
kCGLineCapButt, // 默认
kCGLineCapRound, // 轻微圆角
kCGLineCapSquare // 正方形
*/
path.lineCapStyle =kCGLineCapRound;
/*
kCGLineJoinMiter, // 默认表示斜接
kCGLineJoinRound, // 圆滑衔接
kCGLineJoinBevel // 斜角连接
*/
path.lineJoinStyle =kCGLineJoinBevel;
// 设置填充颜色
UIColor *fillColor = [UIColorgreenColor];
[fillColor set];
[path fill];
// 设置画笔颜色
UIColor *strokeColor = [UIColorblueColor];
[strokeColor set];
// 根据我们设置的各个点连接
[path stroke];
}
- (void)drawCiclePath
{
// 传的是正方形就可以画圆了(长方形--椭圆)
UIBezierPath *path = [UIBezierPathbezierPathWithOvalInRect:CGRectMake(230,20, 100, 100)];
// 设置填充颜色
UIColor *fillColor = [UIColorgreenColor];
[fillColor set];
[path fill];
// 设置画笔颜色
UIColor *strokeColor = [UIColorblueColor];
[strokeColor set];
// 根据我们设置的各个点连接
[path stroke];
}
- (void)drawRoundedRectPath
{
// 矩形的所有角都变成圆角
// UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 130, 100, 50) cornerRadius:10];
// 指定矩形的某个角为圆角
UIBezierPath *path = [UIBezierPathbezierPathWithRoundedRect:CGRectMake(20,130, 100, 50)byRoundingCorners:UIRectCornerBottomRightcornerRadii:CGSizeMake(15,15)];
// 设置填充颜色
UIColor *fillColor = [UIColorgreenColor];
[fillColor set];
[path fill];
// 设置画笔颜色
UIColor *strokeColor = [UIColorblueColor];
[strokeColor set];
// 根据我们设置的各个点连线
[path stroke];
}
// 画弧
- (void)drawARCPath
{
constCGFloat pi =3.14159265359;
CGPoint center =CGPointMake(230,230);
UIBezierPath *path = [UIBezierPathbezierPathWithArcCenter:centerradius:100startAngle:0endAngle:kDegreesToRadians(145)clockwise:YES];
// 有什么区别?
path.lineCapStyle =kCGLineCapRound;
path.lineJoinStyle =kCGLineJoinRound;
path.lineWidth =5.0;
UIColor *strokeColor = [UIColorredColor];
[strokeColor set];
[path stroke];
}
// 画二次贝塞尔曲线
- (void)drawSecondBezierPath
{
UIBezierPath *path = [UIBezierPathbezierPath];
// 首先设置一个起点
[path moveToPoint:CGPointMake(20,230)];
// 添加二次曲线(设置终端点和控制点)
[path addQuadCurveToPoint:CGPointMake(120,350) controlPoint:CGPointMake(self.frame.size.width / 2, 120)];
path.lineCapStyle =kCGLineCapRound;
path.lineJoinStyle =kCGLineJoinRound;
path.lineWidth =5.0;
UIColor *strokeColor = [UIColorredColor];
[strokeColor set];
[path stroke];
}
// 画三次贝塞尔曲线
- (void)drawThirdBezierPath
{
UIBezierPath *path = [UIBezierPathbezierPath];
// 设置起始端点
[path moveToPoint:CGPointMake(20,150)];
// 设置终止端点和控制点1、控制点2
[path addCurveToPoint:CGPointMake(300,150) controlPoint1:CGPointMake(160,0) controlPoint2:CGPointMake(160,250)];
path.lineCapStyle =kCGLineCapRound;
path.lineJoinStyle =kCGLineJoinRound;
path.lineWidth =5.0;
UIColor *strokeColor = [UIColorredColor];
[strokeColor set];
[path stroke];
}
@end
- UIBezierPath贝塞尔曲线
- 贝塞尔曲线UIBezierPath 详解
- 贝塞尔曲线UIBezierPath
- UIBezierPath - 贝塞尔曲线
- iOS UIBezierPath--贝塞尔曲线
- 贝塞尔曲线 UIBezierPath
- 贝塞尔曲线 UIBezierPath
- CGContextRef + UIBezierPath贝塞尔曲线
- iOS贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- git fork代码后保持更新同步
- Android Studio导入Fresco
- ( Leetcode 61 ) Rotate List
- 七种WebSocket框架的性能比较
- java 反射详解
- 贝塞尔曲线 UIBezierPath
- python入门,自制小爬虫获得百度贴吧内容
- LNK2005
- Leetcode.258. Add Digits
- 【连载】关系型数据库是如何工作的?(1) - 前言
- PKU 3013 Big Christmas Tree 最短路 spfa
- ubuntu 16.04 编译opencv3.1,opencv多版本切换
- 一些统计特征与统计图的绘制-matlab
- 【HUSTOJ】1019: 求1+1/2+1/3+...+1/n