2017-04-23 81 views
1

我想添加半径到UIView的左下角和右下角,然后只在同一个UIView的底部投影。 我已经通过解决方案,其中所有的角落都提供半径,然后影子。这工作正常。但是当我使用UIBeizerPath向底角添加半径时,shadow属性似乎不起作用。 我正在使用Objective-C和XCode 8.1。 我该怎么办?底角圆角半径和阴影只在目标C中UIView底部

使用下面的代码底角获取它们的半径,但阴影属性不起作用。

UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; 

[testView setBackgroundColor:[UIColor yellowColor]]; 

// shadow 
testView.layer.shadowColor = [UIColor colorWithRed:156.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1.0f].CGColor; 
testView.layer.shadowOffset = CGSizeMake(0.0f, 2.0f); 
testView.layer.shadowRadius = 4.0f; 
testView.layer.shadowOpacity = 0.5f; 

UIBezierPath *path = [UIBezierPath bezierPath]; 
[path moveToPoint:CGPointMake(0.0, 0.0)]; 
[path addLineToPoint:CGPointMake(0.0, CGRectGetHeight(testView.frame))]; 
[path addLineToPoint:CGPointMake(CGRectGetWidth(testView.frame), CGRectGetHeight(testView.frame))]; 
[path addLineToPoint:CGPointMake(CGRectGetWidth(testView.frame), 0.0)]; 
testView.layer.shadowPath = path.CGPath; 

//bottom corners radius 
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:testView.bounds   
               byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)   
                cornerRadii:CGSizeMake(2.0, 2.0)]; 
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame = self.view.bounds; 
maskLayer.path = maskPath.CGPath; 
testView.layer.mask = maskLayer; 
+0

添加相关的代码和截图与当前的结果。 –

回答

0

面具掩盖了阴影。你需要在另一个视图中有两个视图。将蒙版应用于内部视图并将阴影应用于外部视图。

+0

可以使用多个图层而不是多个视图来完成吗? – coderex

+0

我从来没有这样实现过,但它可能会工作。 –

+0

如果我将角半径蒙版应用于内部视图,它将其cliptobounds设置为true,并且outerview的阴影不显示! – coderex