如何绘制一个三angular形的UIButton
我真的挖了IFTTT右下angular的button,如图(右下)所示。
我尝试过使用CGContext
和UIBezierPath
来匹配效果,但是我根本不知道如何正确使用它。 有没有人有一些想法/代码如何做到这一点?
谢谢!
首先使用CAShapeLayer创build一个蒙版
CAShapeLayer * shapeLayer = [CAShapeLayer layer]; //Use these to create path CGMutablePathRef path = CGPathCreateMutable(); // CGPathMoveToPoint // CGPathAddLines shapeLayer.path = path;
然后设置你的button的面具
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;
和屏幕截图:
做一个方形的button,在其中放置一个三angular形的图像。 那也不行吗? 为了使错觉更好,请为onclick()事件和ontouch()绘制单独的图像。 禁用默认button按下并单击buttonanimation,使其看起来真实。