【问题标题】:How to remove shadow behind popovers on iOS 9?如何在 iOS 9 上移除弹出框后面的阴影?
【发布时间】:2015-12-17 09:07:10
【问题描述】:

在 iOS 8 中,弹出框没有阴影。现在在 iOS 9 中,有一个非常沉重且影响深远的阴影,在纯白色背景上看起来不太理想。如何移除该阴影,而是在弹出框周围添加一条浅灰色细线?或者至少减少或减轻重量。

这发生在显示操作表、使用.Popover UIModalPresentationStyle 呈现视图控制器以及可能在其他情况下。

弹出框转场:

行动表:

UIActionSheet(title: "Title", delegate: nil, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Destroy").showInView(sender as! UIView)

【问题讨论】:

  • 如果您有一个用例说明为什么您的弹出框看起来应该与其他人的不同,我建议向 Apple 提交增强请求。阴影效果由 UIPopoverPresentationController 绘制,但您无法干预或自定义其行为。
  • 没有你想要的 API。如果你需要的话,创建你自己的没有阴影的“popover”类。
  • @Joey,你有没有发现什么,你不觉得我的回答是对的吗?

标签: ios uipopovercontroller popover ios9


【解决方案1】:

您可以使用UIPopoverBackgroundView 制作自己的自定义弹出框背景

UIPopoverBackgroundView 实现的initWithFrame 中,您可以使用[UIColor clearColor 作为投影。

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.layer.shadowColor = [[UIColor clearColor] CGColor];
    }

    return self;
}

【讨论】:

  • 奇怪的是,颜色似乎是您可以更改的唯一属性。我还尝试更改其他阴影属性,如半径、不透明度等,但无济于事
【解决方案2】:

已接受答案的 Swift 4 版本。

override init(frame: CGRect) {
    super.init(frame: frame)    
    layer.shadowColor = UIColor.clear.cgColor
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多