gpt4 book ai didi

ios - 画三角形 iOS

转载 作者:可可西里 更新时间:2023-11-01 04:04:42 24 4
gpt4 key购买 nike

下面的代码正在画一个圆,我如何修改现有代码来画一个三角形?

    _colorDotLayer = [CALayer layer];

CGFloat width = self.bounds.size.width-6;
_colorDotLayer.bounds = CGRectMake(0, 0, width, width);
_colorDotLayer.allowsGroupOpacity = YES;
_colorDotLayer.backgroundColor = self.annotationColor.CGColor;
_colorDotLayer.cornerRadius = width/2;
_colorDotLayer.position = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);

最佳答案

虽然显示了几个 Core Graphics 解决方案,但我想添加一个基于 Core Animation 的解决方案。

- (void)viewDidLoad
{
[super viewDidLoad];
UIBezierPath* trianglePath = [UIBezierPath bezierPath];
[trianglePath moveToPoint:CGPointMake(0, view3.frame.size.height-100)];
[trianglePath addLineToPoint:CGPointMake(view3.frame.size.width/2,100)];
[trianglePath addLineToPoint:CGPointMake(view3.frame.size.width, view2.frame.size.height)];
[trianglePath closePath];

CAShapeLayer *triangleMaskLayer = [CAShapeLayer layer];
[triangleMaskLayer setPath:trianglePath.CGPath];

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0, size.width, size.height)];

view.backgroundColor = [UIColor colorWithWhite:.75 alpha:1];
view.layer.mask = triangleMaskLayer;
[self.view addSubview:view];
}

代码基于我的博文。

关于ios - 画三角形 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25578090/

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