gpt4 book ai didi

ios - 用核心图形绘制正方形和子弹箭头

转载 作者:行者123 更新时间:2023-11-28 19:01:49 27 4
gpt4 key购买 nike

是否可以在 objective-c 中绘制以下内容?我尝试使用该图像,但它像素化了。所以我认为最好以编程方式绘制它。有人可以为我提供一些示例代码来实现这一点。

谢谢。

enter image description here

最佳答案

使用 CAShapeLayer 并为其分配描述形状的路径:

- (UIBezierPath *)createBubblePathInFrame:(CGRect) frame{
CGFloat arrowInset = 10;
CGFloat arrowHeight = 10;
CGFloat arrowWidth = 20;

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, arrowHeight)];
[path addLineToPoint:CGPointMake(arrowInset, arrowHeight)];
[path addLineToPoint:CGPointMake(arrowInset+arrowWidth/2, 0)];
[path addLineToPoint:CGPointMake(arrowInset+arrowWidth, arrowHeight)];
[path addLineToPoint:CGPointMake(frame.size.width, arrowHeight)];
[path addLineToPoint:CGPointMake(frame.size.width, frame.size.height)];
[path addLineToPoint:CGPointMake(0, frame.size.height)];
[path addLineToPoint:CGPointMake(0, arrowHeight)];
return path;
}

像这样使用它:

    CAShapeLayer *shapelayer  = [CAShapeLayer layer];
shapelayer.frame = CGRectMake(50, 50, 200, 100);
shapelayer.path = [self createBubblePathInFrame:shapelayer.bounds].CGPath;
shapelayer.fillColor = [UIColor grayColor].CGColor;
shapelayer.strokeColor = [UIColor redColor].CGColor;
shapelayer.lineWidth = 1;
[self.view.layer addSublayer:shapelayer];

或者在drawRect中自己画:

[[UIColor grayColor] setFill];
[bezierPath fill];
[[UIColor redColor] setStroke];
[bezierPath stroke];

关于ios - 用核心图形绘制正方形和子弹箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24269173/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com