如何创建自定义Shaped UIView?

时间:2014-10-30 12:45:42

标签: objective-c uiview ios8 mask cashapelayer

我想在Star,Pentagon,Hexagon和其他自定义形状中创建一个UIView。

我想在自定义形状中绘制。

我创建了一个bezierPath并尝试将UIView屏蔽到它。 但它不起作用

CGFloat x=48;
CGFloat y=306;
oval2Path  = UIBezierPath.bezierPath;
[oval2Path moveToPoint: CGPointMake(x+340, y+427.5)];
[oval2Path addLineToPoint: CGPointMake(x+476.95, y+523.2)];
[oval2Path addLineToPoint: CGPointMake(x+424.64, y+678.05)];
[oval2Path addLineToPoint: CGPointMake(x+255.36, y+678.05)];
[oval2Path addLineToPoint: CGPointMake(x+203.05, y+523.2)];     [oval2Path closePath];
CAShapeLayer *mask = [CAShapeLayer layer];
mask.path = oval2Path.CGPath;
FinalAlgView *myView=[[FinalAlgView alloc]initWithFrame:CGRectMake(0,0,800,800)];
myView.backgroundColor=[UIColor whiteColor];
myView.layer.mask = mask;

[self.view bringSubviewToFront:drawShape];

[self.view addSubview:myView];

无论如何都要将UIView创建为自定义形状

0 个答案:

没有答案