【问题标题】:Bottom Corner Radius and shadow only at bottom ofUIView in Objective C仅在Objective C中UIView底部的底角半径和阴影
【发布时间】: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


【解决方案1】:

面具正在掩盖阴影。你需要有两个视图一个在另一个里面。将遮罩应用于内部视图,将阴影应用于外部视图。

【讨论】:

  • 可以使用多层而不是多个视图来完成吗?
  • 我从来没有这样实现过,但它可能会起作用。
  • 如果我将角半径遮罩应用到内部视图,它会将其剪辑边界设置为 true,并且不会显示外部视图的阴影!
猜你喜欢
  • 1970-01-01
  • 2017-08-23
  • 2019-01-17
  • 1970-01-01
  • 2014-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多