lundi 29 décembre 2014

How to determine the Today extension left margin properly in iOS 8?

I'm trying to find out how to calculate the actual left margin in my Today extension main view to align the contents to the rest of the Today view.


Here's a screenshot of the Today extension (green = my extension's main view) using iPhone 6 Plus simulator in both portrait and landscape mode:


Screenshot of the Today extension


The red dashed line in the screenshots illustrates the line I'm trying to align the red and blue UILabels to. It seems that the red line - main views left border alignment is different in each device: iPhone 5x, iPhone 6 and iPads.


Currently, the main view gets resized by iOS to the maximum width, and both the UILabels are attached with self.view.layoutMargin = UIEdgeInsetsZero to the left border.


It seems that the UIViews layoutMargin isn't the solution here, the values seem to be the default UIView values (8 pixels all edges).


How do I align the two UILabels to the dashed line?


Edit:


The behavior can be reproduced using a clean Xcode project (I'm using Xcode 6.1.1, iOS 8.1 and Swift):



  1. Create an empty Xcode project (A single-view application)

  2. Add a new Target: Extensions > Today extension

  3. From the Today extension group, find MainInterface.storyboard and make the main view background green and Hello world UILabel background red: enter image description here


The result in iPhone 6 Plus simulator: enter image description here




Aucun commentaire:

Enregistrer un commentaire