Size class specifically for portrait 3.5 inch (iPhone 4S) Xcode 6?

前端 未结 5 2135
遇见更好的自我
遇见更好的自我 2020-12-18 18:52

I\'m tuning my UI App, but I got an issue that I can\'t solve.

As I can see Compact height affects all iPhones under 4.7 inches, but my UI is fine except for the iPh

5条回答
  •  醉梦人生
    2020-12-18 19:16

    Swift 5.0 code for Pavel Alexeev's solution., accounting for some syntax updates and also screen width because I've found that if the device is being held in the landscape orientation when the app is launched, the screen height is not the actual portrait height, but the current landscape height. So, I check that the width is accounted for, too. If the height is less than 660 AND the width is less than 375, we have a portrait SE or 5s.

    extension NSLayoutConstraint
    {
        //We use a simple inspectable to allow us to set a value for iphoneSE / 5s.
        @IBInspectable var iPhoneSE_PortraitConstant: CGFloat
            {
            set{
                //Only apply value to iphone SE and 5s devices.
                 if (UIScreen.main.bounds.size.height < 660 && UIScreen.main.bounds.size.width < 330)
                {
                    self.constant = newValue;
                }
            }
            get
            {
                return self.constant;
            }
        }
    }
    

提交回复
热议问题