gpt4 book ai didi

ios - 如何在 UIView 上制作斜角?

转载 作者:可可西里 更新时间:2023-11-01 03:27:49 38 4
gpt4 key购买 nike

这里有很多关于使 UIView 的角变圆的问题。不幸的是,我找不到关于如何制作角度角的任何信息。我如何制作一个以 45 度角切角的 UIView

如果你能告诉我如何使任何个人切角成一定角度,你甚至可以获得一颗奖金(象征性的)金星。

编辑:供引用,here's a link我怀疑与此解决方案有类似实现的问题。我只是不知道我必须改变什么。

最佳答案

首先你需要一 strip 有斜角的路径:

- (CGPathRef) makeAnglePathWithRect: (CGRect)rect withSize:(float) s {

CGPoint one = CGPointMake( rect.origin.x +s, rect.origin.y);
CGPoint two = CGPointMake( rect.origin.x + rect.size.width - s, rect.origin.y);

CGPoint three = CGPointMake( rect.origin.x + rect.size.width, rect.origin.y +s);
CGPoint four = CGPointMake( rect.origin.x + rect.size.width, rect.origin.y + rect.size.height -s);

CGPoint five = CGPointMake( rect.origin.x + rect.size.width-s, rect.origin.y + rect.size.height);
CGPoint six = CGPointMake(rect.origin.x+s, rect.origin.y + rect.size.height);

CGPoint seven = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height-s);
CGPoint eight = CGPointMake(rect.origin.x, rect.origin.y + s);

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path,NULL,one.x, one.y);
CGPathAddLineToPoint(path,NULL,two.x, two.y);
CGPathAddLineToPoint(path,NULL,three.x, three.y);
CGPathAddLineToPoint(path,NULL,four.x, four.y);
CGPathAddLineToPoint(path,NULL,five.x, five.y);
CGPathAddLineToPoint(path,NULL,six.x, six.y);
CGPathAddLineToPoint(path,NULL,seven.x, seven.y);
CGPathAddLineToPoint(path,NULL,eight.x, eight.y);
CGPathAddLineToPoint(path,NULL,one.x, one.y);

return path;
}

然后需要使用路径指定掩码:

CAShapeLayer *maskLayer = [CAShapeLayer layer];
CGRect bounds = CGRectMake(0.0f, 0.0f, 100, 100); //figure out your bounds

[maskLayer setFrame:bounds];
CGPathRef p = [self makeAnglePathWithRect:bounds withSize:20.0];
maskLayer.path = p;
_myview.layer.mask = maskLayer;

如果你想从任何角落删除角度,摆弄点一八,删除“s”值。您可以使用 size 参数更改从角上切出的三角形的大小。

关于ios - 如何在 UIView 上制作斜角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15035258/

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