作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这里有很多关于使 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/
我是一名优秀的程序员,十分优秀!