美文网首页
iOS 扇形

iOS 扇形

作者: CaptainRoy | 来源:发表于2018-11-19 14:41 被阅读4次
先上效果图
  • PieView.h
@interface PieView : UIView

-(instancetype)initWithCenter:(CGPoint)center radius:(CGFloat)radius bgColor:(UIColor *)bgColor andstartAngle:(CGFloat)startAngle andendAngle:(CGFloat)endAngle;

@end
-(instancetype)initWithCenter:(CGPoint)center radius:(CGFloat)radius bgColor:(UIColor *)bgColor andstartAngle:(CGFloat)startAngle andendAngle:(CGFloat)endAngle {
    
    self = [super init];
    if (self) {
        //设置self的frame和center
        self.backgroundColor = bgColor;
        self.frame = CGRectMake(0, 0, radius * 2, radius * 2);
        self.center = center;
        
    
        //特别注意:贝塞尔曲线的radius必须为self高度的四分之一,CAShapeLayer的线宽必须为self高度的二分之一
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius / 2 startAngle:startAngle endAngle:endAngle clockwise:YES];
        
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.path = path.CGPath;
        maskLayer.fillColor = [UIColor clearColor].CGColor;
        maskLayer.strokeColor = bgColor.CGColor;
        maskLayer.lineWidth = radius; //等于半径的2倍,以圆的边缘为中心,向圆内部伸展一个半径,向外伸展一个半径,所以看上去以为圆的半径是self高度的一半。
        self.layer.mask = maskLayer;
    }
    
    return self;
}
  • 实现
CGPoint point = CGPointMake(150, 150);
    PieView *redView = [[PieView alloc] initWithCenter:point radius:50 bgColor:[UIColor redColor] andstartAngle:-M_PI/2 andendAngle:0.0];
    [self.view addSubview:redView];
    
    PieView *blueView = [[PieView alloc] initWithCenter:point radius:70 bgColor:[UIColor blueColor] andstartAngle:0.0f andendAngle:M_PI*3/2];
    [self.view addSubview:blueView];

相关文章

  • iOS 扇形

    先上效果图 PieView.h 实现

  • iOS 扇形点击位置

    float distance;//距离 float rads;//弧度 CGPoint point = [tap ...

  • iOS 扇形点击位置

  • iOS - 扇形计时动画

    第一次使用简书,记录下平时写的demo, 因为最近时间比较闲,所以找了些网上的效果下载下来学习下,首先说明这是从别...

  • iOS开发学习-扇形动画

    前言:最近比较闲,正好利用这段时间把现在项目用的东西封装一下,方便以后复用,当然好的东西还是要分享。一起学习,一起...

  • iOS 扇形图动画效果

    动画效果如图所示: 这天儿是真特么热啊,现在的基本状态就是:晚上热的睡不着、早上困得醒不来、白天工作没精神……照这...

  • 扇形进度条 - iOS

    绘制扇形进度条 背景:上传文件的时候,需要有上传进度,这次需要一个扇形的进度条,示例图如下: 废话不多说,上代码:...

  • iOS星盘,浅谈如何实现

    IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、...

  • 扇形

    border-radius属性是一个最多可指定四个 border -*- radius 属性的复合属性 div{ ...

  • 扇形

    上班路上遇到住一个小区的钟工,他骑着电动车在我前面,虽然住在一起,由于上班出发时间不一样,很少遇到。 到了翠湖二路...

网友评论

      本文标题:iOS 扇形

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