Storyboard warning : First baseline layout attribute before iOS 8.0 - ios

I can't figure out how to get rid of this warning, I'm using a storyboard with many viewControllers (with labels, textfields and a lot of constraints ) all of them have been created almost the same way.
When I click on the warning it highlights a UILabel inside a scrollView :
This scrollView has many UILabels with constraints, I tried everything I could find on so including : Attribute Unavailable: First baseline layout attribute on iOS versions prior to 8.0
This Warning doesn't cause my app to crash,I've tried on the simulator and an iPhone 4 (ios 7.1.2). But I'm worried about the AppStore approval.

I think the issue is you have many constraints that are using NSLayoutAttributeFirstBaseline and when you click on the warning Xcode is pointing to wrong constraint.
To identify the constraints search in Xcode with "firstBaseline". Change all constraints that are using NSLayoutAttributeFirstBaseline.
Note: You may need to adjust your views. In my case NSLayoutAttributeBaseline worked well.
NSLayoutAttributeFirstBaseline
The object’s baseline. For objects with more than one line of text, this is the baseline for the topmost line of text.
The object’s baseline. For objects with more than one line of text, this is the baseline for the topmost line of text.
Available in iOS 8.0 and later.
NSLayoutAttributeBaseline
The object’s baseline.
The object’s baseline.
Available in iOS 6.0 and later.

Related

Xcode 7 to Xcode 8 Storyboard Constraint Warnings

I just converted my Xcode project from Xcode 7.3 to Xcode 8 GM and I am getting over 80 constraint warnings. In Xcode 7, my storyboards were "big squares" rather than a specific iPhone size. Now, with Xcode 8, you can change to the different iPhone and iPad sizes. My constraints are still showing up as they were with the more squared-off VCs in Xcode 7. Is there a "quick" fix or do I need to go through my entire app and fix each and every constraint (far more than 80)?
UPDATE: September 20,2016 -> Many bug reports have been filed based on this feed and Apple should be aware of the problem. I will update with an answer as soon as the problem is fixed.
Select all the Scenes(View Controllers) in the Storyboard, show the Size inspector, change the Simulated Size to Freeform, then set Width Height = 600.
Then, those tons of warnings disappear.
I had the same issue when updating to Xcode 8. My storyboard looked just like you describe. Check your warnings/errors. If they all say something like "set vertical hugging priority to X" or "set compression resistance to Y" then you should be able to fix your issue by setting the priorities as suggested.
Click a warning, then in the attribute inspector under the tab with the ruler icon (not sure what that tab is called) you can set the priorities under the Content Hugging Priority and Content Compression Resistance Priority headers. As you update these properties the warnings should start to change to incorrect frame warnings, at which point you can just update the frames.
This might not be a quick fix, but changing a few priorities for some constraints is easier than redoing all the constraints. I hope this helps!
Select the view controllers one by one and press "Update Frames" each time.

Xcode missing constrains although app not using size classes?

I have an older app which is not using size classes and I will not use constrains in this app. I did some changes on the layout (using xcode 7.2) and since than I am getting some errors "missing constraints" although I am NOT using size classes? And it is true from time to time the layout is wrong (but not ever?). How can I turn off constrains for this screen?
If you want to let xcode set constraints then you can select reset to suggested constraints as follows..

Justified or Natural text alignment before iOS 7 Warning

I have an iOS App that is targeted to iOS 6 and above (I know, I know. But a disturbing number of our users are still on iPhones that have never been updated) and I'm seeing a warning when I compile my app:
Justified or Natural text alignment before iOS 7.0
This is seen for each place I've chosen "natural" text alignment for a control in my xib files. This is confusing to me, because the docs clearly state that NSTextAlignmentNatural is "Available in iOS 6.0 and later."
NSString Documentation
No warnings are presented when I set the alignment in the code, only from the xib.
Unfortunately, I am unable to test this myself because I don't have an iOS 6 device. Is this a warning that I just need to ignore, or could issues still arise in the older devices?
I just made a test project and got the same result with a UILabel set to justified. I repeated with a UITextArea and didn't get the error, so it seems to only relate to setting justified on UILabels.
I ran the same code on an iOS 6 device I have here and didn't get a crash, it just stayed left aligned, so you can probably ignore it, but it is very odd.
Perhaps you could try setting attributed text on the UILabels instead and see if the same thing happens.
UILabel set to Left-justif,like this
setting

Inhibit `Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0` warnings

I have an abundant amount of Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0 warnings in my project in ~80 xib files. I have attempted to fix these warnings using answers found here: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0, but this led to AutoLayout issues.
Fixing all the consequential effects is not something our team wants to take on, and furthermore QA. I know how to turn off all warnings for xib files in a target. How do I ignore this specific warning?
Find all the multi-line UILabels in your project (Lines = 0 in Attributes Inspector) and set their Preferred Width property in Size Inspector to 0 (check the Explicit check box).
Check the label constrain, the answer was to click on the constraint, and then look in the Utilities bar (on the right). As shown in the picture below, click on an item and then make sure that "relative to margin" is unchecked.

Layout attributes relative to the layout margin on iOS versions prior to 8.0

What would be causing the following warning (and subsequent alignment issues on iOS 7)?
Attribute Unavailable: Layout attributes relative to the layout margin on iOS versions prior to 8.0
None of the posted answers solved the problem for me. But the reason for this is the following: Xcode 6 creates constraints based on relative margins by default. Those are only available on iOS 8.0 and newer. You get these warnings when your deployment target is set to iOS 7.0 or lower.
The way I fixed the warning:
Click the warning in Xcode
Attribute inspector will open the constraint
Search for item that has margin (see screenshot)
Turn off Relative to margin option
Disable "Prefer margin relative"
Unchecking the "Prefer Margin Relative" checkbox will keep you from getting into the situation where you get this warning.
If you are like me and you built an entire app with constraints before realizing the problem, then things are a bit tougher because Xcode will not easily tell you which constraints are a problem.
In order to avoid rebuilding all of my constraints, I resorted to looking at the actual .storyboard file and I looked for constraints like this:
<constraint firstItem="vId-..." firstAttribute="top" secondItem="In7-..." secondAttribute="topMargin" id="C0H-..."/>
Notice "topMargin". The attributes ending in "Margin" cause the warning. I went through and identified the constraints in the file this way, then I removed and re-created them in IB. After that, this warning went away.
I suspect this should also resolve some inconsistencies between iOS 7 and iOS 8 constraint handling, although I am still encountering some differences in behavior, even after addressing all Xcode warnings.
I'm currently in the same situation as I'm creating an app in Xcode 6 that targets iOS7 and 8. That warning appears because the constraints relative to the margin aren't available in iOS7, but they are created by default in Xcode 6.
You can absolutely go back and edit the constraint to not use that 'Relative to margin' feature as suggested by the other answers to this question.
When creating new constraints, I hold down the Option key when choosing which kind of constraint to create. This gives me the ability to create a constraint that's not based on the margin right away so I don't have to go back and fix it afterwards.
Xcode 6 creates constraints based on relative margins by default.
So, if you want to force remove all baselines attributes and don't want to search all bad constrains in Interface Buidler, to support iOS 7, I can recommend this way
To find and remove all dummy strings with "Baseline" in constraints you can do this:
Close Xcode
Open your stroyboard file in your favorite text editor, that supports regexp.
Find and remove from storyboard file all strings by pattern: .*"baseline".*\n
Now save file and open it in Xcode
Fix all appeared misaligns: find all warnings and press "Update constraints for all views" to save original position of all views.
Profit!
UPD:
I found that "baseline" constraints causes crashes also, but Xcode doesn't show any warnings about these constrains!
To fix it - remove from storyboard file all strings by pattern: .*"baseline".*\n
I took a non programmer approach.
I knew which view controler was causing the 8.0 margin message. So, I went to my constraint list. I had 33. I've remove every one that was causing the 8.0 margin message. I went down to 20 (So 11 was problem).
Select 32 over 33 delete and see the result. Select 31 over 33 delete and so on ... Naturally when the message still there ... delete the problematic one.
So it took me 5 minutes to resolve the error message.
Other constraint messages did appear but that's not a big deal.
Ok than, redo and resolve step by step the constraint messages but this time check that all the constraint you add don't provoke the reappearing of the 8.0 margin message. If so, undo and take an other strategy when adding constraints. There's always an other way to add a constraint that work.
That's not what is proposed by Xcode but it will do the job.
At the end, your done.
If you have more than one view controller, and don't know witch one is causing the 8.0 margin message, try to isolate each view controller. May be in a separate test project with a copy and paste or deleting all the other view except one and se the result.
Using the "Create Snapshot" in the file menu can help you if something goes wrong.
Suppressing the warnings: I went through all IB constraints and deleted all that said "First Baseline...". This made all of these warnings go away. However, IB will reintroduce the warnings if you "Add missing constraints" or "reset to suggested constraints".
Possible cause: From a fresh Xcode 6.1 project, I copy/pasted ViewControllers in Storyboard (lazily), using "reset to suggested constraints". Then changed the project target from 8.0 to 7.1. This caused the warnings to pop up. I noticed that the warnings only occurred on certain of my ViewControllers, which I believe were the ones I copied/pasted in Storyboard.
Suggestion: If targeting 7.1, set it up front before using IB. Don't copy/paste view controllers in Storyboard. And be wary of "new warnings" when working within IB, so hopefully we can confirm the cause of this annoyance.

Resources