leading or trailing horizontal alignment before iOS 11

IosXcodeAutolayoutStoryboardSafearealayoutguide

Ios Problem Overview


Warning: leading or trailing horizontal alignment before iOS 11

I am getting above warning during compilation on Xcode 9.1 on one of the scenes in a storyboard file. There are other storyboards (with deployment target iOS 10.0) and yet the warning is shown to this specific scene on a specific Storyboard file.

The warning gets suppressed if I change deployment target to iOS 11.0 on the scene where warning is shown but I don't want to do that.

Has anyone come across this case?

Ios Solutions


Solution 1 - Ios

For me the problem was in using trailing leading alignment on UIButton itself.

Safe area seems to be completely fine to use - it's backward compatible and it translates into proper super view margins.

But this feature is iOS 11 only, so use standard left / right alignment instead if you are targeting lower iOS versions.

Easiest way to find out which view is causing the problem is to search for contentHorizontalAlignment="leading" or contentHorizontalAlignment="trailing" in source code for .xib

enter image description here

Solution 2 - Ios

Step 1:

View your offending storyboard as source code: enter image description here

Step 2:

Replace all instances of:

contentHorizontalAlignment="leading"

with:

contentHorizontalAlignment="left"

Step 3:

Replace all instances of:

contentHorizontalAlignment="trailing"

with:

contentHorizontalAlignment="right"

Step 4:

Compile and watch warning disappear.

I find this approach easier when you have a ton of elements that need to be modified. "leading" and "trailing" as 'contentHorizontalAlignment' value types were introduced with iOS 11. iOS 10 doesn't know about "leading" and "trailing" which is the reason for the warning.

Solution 3 - Ios

In the build log, right before the word "warning", you will see an Interface Builder identifier in the form "xxx-yy-zzz". Copy and paste that into the Xcode search bar, and it will find the "offending" control for you. Click on the search result and it will take you right into the storyboard with the corresponding control selected. The rest of the problem can be resolved using the other answers.

Solution 4 - Ios

I had this problem with a whole bunch of buttons that I needed left aligned with a little offset. I removed the storyboard alignment and did it like this in viewDidLoad with an array of the needy buttons.

func indentButtons(buttons: [UIButton?]){
    for i in 0..<buttons.count{
        buttons[i]!.contentHorizontalAlignment = .left
        buttons[i]!.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0)
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPrabhavView Question on Stackoverflow
Solution 1 - IosGrzegorz KrukowskiView Answer on Stackoverflow
Solution 2 - IosetayluzView Answer on Stackoverflow
Solution 3 - IosDavid HoyView Answer on Stackoverflow
Solution 4 - Iosuser462990View Answer on Stackoverflow