我真的很喜欢 IFTTT 右下角按钮,如图(右下)所示。
我尝试使用 CGContext
和 UIBezierPath
来匹配效果,但我根本不知道如何正确实现这一点。有人对如何实现这一点有一些想法/代码吗?
谢谢!
最佳答案
首先使用CAShapeLayer创建一个 mask
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
//Use these to create path
CGMutablePathRef path = CGPathCreateMutable();
// CGPathMoveToPoint
// CGPathAddLines
shapeLayer.path = path;
然后设置按钮的掩码
yourbutton.layer.mask = shapeLayer
yourbutton.masksToBounds = YES;
View 示例
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, CGRectGetHeight(self.testview.frame));
CGPathAddLineToPoint(path, nil, CGRectGetWidth(self.testview.frame), 0);
CGPathAddLineToPoint(path, nil, CGRectGetWidth(self.testview.frame), CGRectGetHeight(self.testview.frame));
CGPathCloseSubpath(path);
shapeLayer.path = path;
self.testview.layer.masksToBounds = YES;
self.testview.layer.mask = shapeLayer;
和屏幕截图:
关于ios - 如何绘制三角形的UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30315337/