0

I have an old project that doesn't uses autolayout and lot of legacy code. I want to make it compatible with iPhone X till I complete a code rewrite of the entire project. I thought of using NotchKit but it doesn't gives expected results. Is there a way to define UIApplication window's custom frame (which is a subrect of the full screen), and then every ViewController respect that bounds?

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

2 Answers2

0

You can find padding of iPhoneX

In swift

if #available(iOS 11.0, *) {
    let window = UIApplication.shared.keyWindow
    let topPadding = window?.safeAreaInsets.top
    let bottomPadding = window?.safeAreaInsets.bottom
    let leftPadding = window?.safeAreaInsets.left
    let rightPadding = window?.safeAreaInsets.right
 }

In Objective C

if (@available(iOS 11.0, *)) {
    UIWindow *window = UIApplication.sharedApplication.keyWindow;
    CGFloat topPadding = window.safeAreaInsets.top;
    CGFloat bottomPadding = window.safeAreaInsets.bottom;
    CGFloat leftPadding = window.safeAreaInsets.left;
    CGFloat rightPadding = window.safeAreaInsets.right;
}
user6788419
  • 7,196
  • 1
  • 16
  • 28
  • Do I need to use paddings in each and every UIView I create? That's not the objective I had. – Deepak Sharma Dec 01 '17 at 09:28
  • see this https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/ – user6788419 Dec 01 '17 at 09:30
  • Doesn't serves my purpose. All I want is not to replace reach and every call like subview.frame = CGRectMake(0,0,width,height) to subview.frame = CGRectMake(leftPadding, topPadding, width, height). – Deepak Sharma Dec 01 '17 at 17:33
0

In Storyboard file, you must check at Use Safe AreaLayout Guides

enter image description here

tai do
  • 124
  • 6