iOS 创建一个小三角指示器
2018-08-30 本文已影响15人
JohnayXiao
效果
![](https://img.haomeiwen.com/i2284089/dbee40ce5bd8f96b.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