iPhone X-设置居家指示器周围区域的颜色 [英] iPhone X - Set the color of the area around home indicator

查看:111
本文介绍了iPhone X-设置居家指示器周围区域的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试将工作表与iPhone X的安全区域对齐时,我对Xcode还是很陌生,它在工作表下方留有透明区域.

I'm pretty much new to Xcode when trying to align a sheet to the safe area of iPhone X, it leaves a transparent area below the sheet.

有没有一种方法可以设置该区域的填充范围,而不扩大页面范围或在安全区域之外对齐?

Is there a way to set the fill of that area w/o expanding the sheet or align outside of the safe area?

推荐答案

这是我的小扩展名. 如果有人可以提出改进建议,不要通过魔术数字"标签访问添加的视图-欢迎光临!

Here is my tiny extension. If anybody can suggest an improvement to not access added view by "magic number" tag - welcome!

extension UIViewController {

private static let insetBackgroundViewTag = 98721 //Cool number

func paintSafeAreaBottomInset(withColor color: UIColor) {
    guard #available(iOS 11.0, *) else {
        return
    }
    if let insetView = view.viewWithTag(UIViewController.insetBackgroundViewTag) {
        insetView.backgroundColor = color
        return
    }

    let insetView = UIView(frame: .zero)
    insetView.tag = UIViewController.insetBackgroundViewTag
    insetView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(insetView)
    view.sendSubview(toBack: insetView)

    insetView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    insetView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    insetView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
    insetView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true

    insetView.backgroundColor = color
}

}

这篇关于iPhone X-设置居家指示器周围区域的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆