美文网首页
iOS 关乎绘制圆弧的一个细节

iOS 关乎绘制圆弧的一个细节

作者: 雪_晟 | 来源:发表于2017-07-21 14:08 被阅读55次
1.png
#import "LXBezierPathView.h"
@interface LXBezierPathView()
@property(nonatomic,strong)UILabel *lable;
@end
@implementation LXBezierPathView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        self.lable =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
        self.lable.text = @"哈哈哈";
        self.lable.textAlignment = NSTextAlignmentCenter;
        self.lable.center = CGPointMake((frame.size.width )/2, (frame.size.width)/2);
        
        [self addSubview:self.lable];
    }
    return self;
}
-(void)drawRect:(CGRect)rect{
    CAShapeLayer *shapeLayer =[[CAShapeLayer alloc]init];
    
    shapeLayer.frame = CGRectMake(0, 0, rect.size.width, rect.size.width);
    shapeLayer.lineWidth = 10;
    
    shapeLayer.fillColor =[UIColor clearColor].CGColor;
    shapeLayer.strokeColor =[UIColor redColor].CGColor;
    
    
    CGPoint center =  CGPointMake((rect.size.width )/2, (rect.size.width)/2);
   
    UIBezierPath *bezierPath =[UIBezierPath bezierPathWithArcCenter:center radius:(rect.size.width )/2 startAngle:-0.5 *M_PI endAngle:0.5 *M_PI clockwise:YES];
    shapeLayer.path = bezierPath.CGPath;
    
    [self.layer insertSublayer:shapeLayer above:shapeLayer];
    
}


我们绘制圆弧的时候,会设置贝塞尔曲线的半径为view的一半, 可是真正显示出来,会发现多了一点。这一点的长度刚好是线宽的一般。

所以需要处理的是

 UIBezierPath *bezierPath =[UIBezierPath bezierPathWithArcCenter:center radius:(rect.size.width  - 线宽)/2 startAngle:-0.5 *M_PI endAngle:0.5 *M_PI clockwise:YES];

相关文章

  • iOS 关乎绘制圆弧的一个细节

    我们绘制圆弧的时候,会设置贝塞尔曲线的半径为view的一半, 可是真正显示出来,会发现多了一点。这一点的长度刚好是...

  • IOS 绘制圆弧

    UIBezierPath*bezierPath = [UIBezierPathbezierPath]; //M_P...

  • IOS绘制圆弧

    绘制圆弧 就是一个圆形的一部分只需掌握方法的各个参数的含义。 掌握CGContextAddArc参数的各个含义。C...

  • Paint类和Canvas类中的方法

    drawArc方法:绘制圆弧 【功能说明】该方法用于在画布上绘制圆弧,通过指定圆弧所在的椭圆对象、起始角度、终止角...

  • ios绘图基础

    ios常见的图形绘制 画线 画圆、圆弧 画矩形,画椭圆,多边形 画图片 画文字 1:ios绘图基础 几个基本的概念...

  • 迅捷CAD编辑器怎么在使用圆弧命令?怎么操作?

    在迅捷CAD编辑器中怎么绘制圆弧命令?关于圆弧绘制的话,大家也应该都是很熟悉了,当我们需要在CAD里面绘制一些圆弧...

  • 绘图相关小Demo

    扇形进度指示器 SimpleProgress 优酷播放按钮 步骤 绘制圆弧,绘制竖线,绘制三角 竖线圆弧添加str...

  • Canvas使用方法总结

    引入Canvas标签 绘制直线 绘制矩形 绘制圆弧 绘制文本 绘制图片 我的github:https://gith...

  • 一步一步去实现一个pie

    1.画圆弧 在canvas中,可以通过arc来绘制一个圆或者火狐,我们先来看看绘制之后的圆和圆弧长什么样上代码 上...

  • canvas

    canvas 简介 1熟悉api 2做一个动画 绘制矩形 绘制路径 线 圆弧 色彩 线型styles

网友评论

      本文标题:iOS 关乎绘制圆弧的一个细节

      本文链接:https://www.haomeiwen.com/subject/kicekxtx.html