swift - 如何在 Swift 中的弹出窗口及其箭头上添加边框颜色?

标签 swift uiview calayer popover uipopoverpresentationcontroller

我的应用程序中有以下弹出窗口:

enter image description here

但我希望它看起来像这个经过编辑的图像(请注意,即使箭头也有边框):

enter image description here

现在这可能吗?我已经在 UIViewController 中尝试了以下内容:

self.view.layer.borderColor = UIColor.white.cgColor
self.view.layer.borderWidth = 2

但这对箭头不起作用。有什么转机吗?

最佳答案

我花了一段时间,但终于解决了这个问题。它以一个通用的 UiPopoverPresentationController 开始。目前还没有什么特别之处。

此 Controller 将自身隐藏在 viewWillAppearviewDidAppear 之间的某处。因此,当弹出框成形时,我采用了它自己的 mask 路径,并用它来制作带有笔触的子层。

    override func viewWillLayoutSubviews() {
        guard let shapeLayer = view.superview?.superview?.mask?.layer as? CAShapeLayer else { return }
        let borderLayer = CAShapeLayer()
        borderLayer.path = shapeLayer.path
        borderLayer.lineWidth = 4
        borderLayer.strokeColor = borderColor.cgColor
        borderLayer.fillColor = UIColor.clear.cgColor
        borderLayer.frame = shapeLayer.bounds
        view.superview?.superview?.layer.addSublayer(borderLayer)
    }

结果如下所示。

Result looks like this

关于swift - 如何在 Swift 中的弹出窗口及其箭头上添加边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53096119/

相关文章:

ios - 如何在 UIImageView 之上添加交互式 UILabel?

swift - 如何计算 Swift 中字符串中的单词数?

ios - 带有 UICollectionView 的 xib - 不符合键值编码

iphone - Core Plot 图高度未填满托管 View

ios - 无法选择或打印搜索栏过滤数组

swift - 为什么 didSet 不起作用?

iphone - 如何获取UIView的 subview ?

ios - 如何在 CALayer 上进行转换?

objective-c - cocoa 层支持的 View : When can I NOT enable layer-backing on a window content view?

ios - UITableViewCell 上的循环 UIImageView 在第一次加载时不起作用