Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone X - Set the color of the area around home indicator

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?

enter image description here

like image 785
Nam Dang Avatar asked Jan 03 '23 07:01

Nam Dang


1 Answers

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
}

}

like image 79
SSemashko Avatar answered Jan 20 '23 15:01

SSemashko