继承UIView, 自定义一个View
重写方法
- (void)drawRect:(CGRect)rect
完整代码:
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:50 startAngle:0 endAngle:360 clockwise:YES];
[path stroke];
UIBezierPath *path2 = [UIBezierPath bezierPath];
[path2 moveToPoint:CGPointMake(100, 100)];
[path2 addLineToPoint:[self calcCircleCoordinateWithCenter:CGPointMake(100, 100) angle:10 radius:60]];
[path2 stroke];
}
#pragma mark 计算圆圈上点在IOS系统中的坐标
- (CGPoint)calcCircleCoordinateWithCenter:(CGPoint)center angle:(CGFloat)angle radius:(CGFloat)radius
{
CGFloat x2 = radius * cosf(angle * M_PI / 180);
CGFloat y2 = radius * sinf(angle * M_PI / 180);
return CGPointMake(center.x + x2, center.y - y2);
}