iOS 创建一个小三角指示器

2018-08-30  本文已影响15人  JohnayXiao

效果

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
上一篇下一篇

猜你喜欢

热点阅读