我确实挖了IFTTT右下角的按钮,如图(右下图)所示。
我尝试使用CGContext
和UIBezierPath
来匹配效果,但是我只是不知道该怎么做。是否有人对如何实现此目标有想法/代码?
谢谢!
最佳答案
首先使用CAShapeLayer创建遮罩
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
//Use these to create path
CGMutablePathRef path = CGPathCreateMutable();
// CGPathMoveToPoint
// CGPathAddLines
shapeLayer.path = path;
然后设置你的按钮的面具
yourbutton.layer.mask = shapeLayer
yourbutton.masksToBounds = YES;
视图示例
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;
屏幕截图: