美文网首页
iOS 创建一个小三角指示器

iOS 创建一个小三角指示器

作者: JohnayXiao | 来源:发表于2018-08-30 09:52 被阅读15次

    效果

    QQ20180830-094400@2x.png

    直接用initFrame方法创建

    [[TriangleView alloc] initWithFrame:CGRectMake(0,  - 8, 16, 8)];
    

    .m文件只重写一个drawRect方法就OK

    @implementation TriangleView
    
    - (void)drawRect:(CGRect)rect
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        CGContextMoveToPoint(context, self.frame.size.width / 2.0, 0);
        
        CGContextAddLineToPoint(context, 0, self.frame.size.height);
        
        CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height);
        
        CGContextClosePath(context);
        
        [[UIColor clearColor] setStroke];
        
        [[UIColor whiteColor] setFill];
        
        CGContextDrawPath(context, kCGPathFillStroke);
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS 创建一个小三角指示器

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