// ViewController.m
// 画方画圆
//
// Created by Admin on 2019/5/5.
// Copyright © 2019年 JZY. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *v;
@end
@implementation ViewController
{
CAShapeLayer *shapeLayer;
CGPoint startPoint;
CGPoint endPoint;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview: self.v];
self.v.frame = CGRectMake(50, 50, 200, 200);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
shapeLayer = [CAShapeLayer new];
shapeLayer.backgroundColor = [UIColor purpleColor].CGColor;
shapeLayer.fillColor = [UIColor whiteColor].CGColor; //填充颜色
shapeLayer.strokeColor = [UIColor redColor].CGColor; //边框颜色
shapeLayer.lineWidth = 2.0f; //边框的宽度
[self.v.layer addSublayer:shapeLayer];
self.v.layer.backgroundColor = UIColor.greenColor.CGColor;
UITouch *touch = [touches anyObject];
startPoint = [touch locationInView:self.v];
// UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(80, 150) radius:80 startAngle:0 endAngle:M_PI*2 clockwise:YES];
// shapeLayer.path = bezierPath.CGPath;
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
endPoint = [touch locationInView:self.v];
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(startPoint.x, startPoint.y, endPoint.x - startPoint.x, endPoint.y - startPoint.y)];
//bezierPathWithOvalInRect 圆
// bezierPathWithRect 方
// UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(point.x, point.y) radius:80 startAngle:0 endAngle:M_PI*2 clockwise:YES];
shapeLayer.path = bezierPath.CGPath;
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
}
- (UIView *)v {
if (!_v) {
_v = [UIView new];
_v.backgroundColor = [UIColor grayColor];
}
return _v;
}
@end
最简单的画方画圆 iOS
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 我的变化是随风潜入夜,润物细无声,不知何时说话我也可以妙语连珠,出口成章,不知何时你可以自信的现在众人面前分享,不...
- 今晚成都沙龙做《场域动力生命系统整合》,我在遥远的香港,也想就这个孩子和这个家庭说几句话: 1任何一个教育工作者都...
- 兰州不苦涩 稀稀拉拉的小雨拍打着路面,又是一个下雨的午后。我静静的坐在窗边,看着窗外水汽氤氲,手指中央着刚刚点燃...