三角矩形背景 三角位于矩形下方

2024-10-11  本文已影响0人  奔跑吧小蚂蚁

import "BaccaratGameBubbleView.h"

@implementation BaccaratGameBubbleView

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGMutablePathRef contourPath = CGPathCreateMutable();

CGFloat x = rect.size.width/2;
CGFloat y = rect.size.height;
CGFloat arrowWidth = 10.0f;
CGFloat arrowHeight = 5.0f;
CGFloat cornerRadius = 4.0f;

CGRect bubbleFrame = CGRectMake(0, 0, rect.size.width, rect.size.height-arrowHeight);

CGPathMoveToPoint(contourPath, NULL, x, y);
CGPathAddLineToPoint(contourPath, NULL, x - arrowWidth / 2, y + (-1) * arrowHeight);

[self drawBubbleBottomShapeWithFrame:bubbleFrame cornerRadius:cornerRadius path:contourPath];

CGPathAddLineToPoint(contourPath, NULL, x + (arrowWidth/2), y - arrowHeight);


CGPathCloseSubpath(contourPath);

CGContextAddPath(context, contourPath);
CGContextClip(context);

// 填充内部颜色
CGContextSetFillColorWithColor(context, [[UIColor blackColor] colorWithAlphaComponent:0.65].CGColor);
CGContextFillRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height));

[self drawBorderWithBorderPath:contourPath context:context];
CGContextRestoreGState(context);

}

https://blog.csdn.net/samuelandkevin/article/details/121580726

上一篇 下一篇

猜你喜欢

热点阅读