UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake( 20, 40)];
[path addLineToPoint:CGPointMake(36, 40)];
[path addLineToPoint:CGPointMake(28, 50)];
CAShapeLayer *layer = [CAShapeLayer layer];
layer.fillColor = [UIColor redColor].CGColor;
layer.path = path.CGPath;
[self.switchTipLabel.layer addSublayer:layer];
- (void)addView{
UIImage *triangle = [self triangleImageWithSize:CGSizeMake(16, 10) tintColor:[UIColor redColor]];
UIImageView *triangleView = [[UIImageView alloc]initWithImage:triangle];
triangleView.frame = CGRectMake(20, tipHeight, 16, 10);
[self.switchTipLabel addSubview:triangleView];
}
- (UIImage *)triangleImageWithSize:(CGSize)size tintColor:(UIColor *)tintColor{
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(size.width/2,size.height)];
[path addLineToPoint:CGPointMake(size.width, 0)];
[path closePath];
CGContextSetFillColorWithColor(ctx, tintColor.CGColor);
[path fill];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
网友评论