ios - 使用 UIBezierPath 和阴影查看?

标签 ios objective-c iphone shadow uibezierpath

我在 UITableViewCell 中有一个 View ,它有 3 个圆角和一个阴影。我正在使用 UIBezierPath 处理圆角,但我无法删除阴影。

这是使用的代码行:

   CGRect bounds2 = cell.backgroundMessageView.bounds;
   UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:bounds2
                                                               byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomRight
                                                                     cornerRadii:CGSizeMake(5, 5)];

   CAShapeLayer *maskLayer2 = [CAShapeLayer layer];
   maskLayer2.frame = bounds2;
   maskLayer2.path = maskPath2.CGPath;


   cell.backgroundMessageView.layer.mask = maskLayer2;

    //drop shadow   

   [cell.backgroundMessageView.layer setShadowColor:[UIColor blackColor].CGColor];
   [cell.backgroundMessageView.layer setShadowOpacity:1];
   [cell.backgroundMessageView.layer setShadowRadius:3.0];
   [cell.backgroundMessageView.layer setShadowOffset:CGSizeMake(2, 2)];

这需要是结果:

enter image description here

有什么想法吗?

谢谢!

最佳答案

解决方案!

    cell.backgroundMessageView.layer.cornerRadius=5;
    CGRect bounds2 = cell.backgroundMessageView.bounds;
    UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:bounds2
                                                                    byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomRight
                                                                          cornerRadii:CGSizeMake(5, 5)];

    CAShapeLayer *maskLayer2 = [CAShapeLayer layer];
    maskLayer2.frame = bounds2;
    maskLayer2.path = maskPath2.CGPath;
    maskLayer2.shadowRadius = 2;
    maskLayer2.shadowOpacity = 0.1;

    maskLayer2.shadowColor =[UIColor blackColor].CGColor;
    maskLayer2.fillColor = [UIColor colorWithRed:252/256.0 green:252/256.0 blue:252/256.0 alpha:1].CGColor;
    maskLayer2.shadowOffset = CGSizeMake(0, 1);


    [cell.backgroundMessageView.layer insertSublayer:maskLayer2 atIndex:0];

关于ios - 使用 UIBezierPath 和阴影查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937499/

相关文章:

ios - 图像作为按钮 C4

ios - 如何在 Table View Xcode 中提供 'real time' 更新

ios - 在 xCode 5 项目中使用 iOS6 If 语句时生成错误

ios - 通过 BLE 通知接收数据包

ios - 获取 Today-Extension 中通知中心的宽度

iphone - 有什么方法可以防止用户删除已安装的应用程序?

iphone - 模拟推送的 NavigationController 的更新 View

iphone - 在现有屏幕上显示小 View /对话框的最佳方式?

iphone - 如何获取有关 UIScrollView 中页面的信息?

ios - 错误 ITMS-90206 无效的包包含不允许的文件 'Frameworks'