我真的挖了IFTTT右下角的按钮,如图所示(右下角)。如何绘制一个三角形UIButton
我试着用CGContext
和UIBezierPath
玩弄相匹配的效果,但我根本不知道够得到这个权利。有没有人有关于如何做到这一点的想法/代码?
谢谢!
我真的挖了IFTTT右下角的按钮,如图所示(右下角)。如何绘制一个三角形UIButton
我试着用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;
和屏幕截图:
制作一个方形按钮,在其中放置一个三角形的图像。这不会工作吗?为了使错觉更好,请为onclick()事件和ontouch()绘制单独的图像。禁用默认按钮按下并按钮单击动画使其看起来真实。
就我个人而言,我不是一个iOS程序员,所以我不知道核心API,但是当我想要一个具有不同形状的按钮时,这就是我通常所做的。 –
请注意,触摸跟踪仍然会像按钮是方形那样工作,这可能无关紧要,但值得注意的是。 –