【发布时间】:2017-04-23 12:16:41
【问题描述】:
我想在 UIView 的左下角和右下角添加半径,然后仅在同一 UIView 的底部放置阴影。 我已经完成了所有角落都提供半径和阴影的解决方案。那工作正常。但是当我使用 UIBeizerPath 将半径添加到底角时,阴影属性似乎不起作用。 我正在使用 Objective-C 和 XCode 8.1。 我该怎么做?
使用下面的代码底角得到它们的半径,但阴影属性不起作用。
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;
【问题讨论】:
-
添加当前结果的相关代码和截图。
标签: ios objective-c uiview