0

I have a today widget for my app and I have been setting the layout of objects in code (Not using auto-layout) however, I need to detect when a user is using an iPhone 6 Plus. The reason for this is because in notification centre on the 6 Plus, there is a border around the edge which cuts off the labels in my widget (in landscape).

The problem is that I have been having issues trying to figure out what height value the screen is in landscape.

This is the code I have right now:

        var height = UIScreen.mainScreen().bounds.size.height

    if UIDevice.currentDevice().orientation.isLandscape && height == 414 {
        totalBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
        currentBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
        budgetNameDisplay.frame.origin.x = 80
        warningLabel.center = view.center
        button.frame = CGRectMake(0, 0, view.bounds.width, view.bounds.height)
    }

Is this the correct value for the screen height in landscape? If so, why are the labels still not moving?

user3746428
  • 11,047
  • 20
  • 81
  • 137

1 Answers1

0

Your code is good but UIDevice.currentDevice().orientation.isLandscape just does not get you correct value.

Seems like there is no bullet-proof solution to detect device orientation for Extensions.

Look at this answer for possible workaround - https://stackoverflow.com/a/26023538/2797141

Community
  • 1
  • 1
xZenon
  • 655
  • 6
  • 18