when I add constraints in Xcode add new constraints, all my 0 and negative 0 turns into standard and it gives some strange output when I set those constraints. How can I fix this?
Is this any new feature of Xcode or issue I don't know?
This is an issue from Xcode and they will resolve it in the next update. Beta version of this update is available on the Apple's website
They have fixed a bug that prevented entering a 0 constant in the constraint popup editors. (54076090)
Related
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?
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
Step 1:
View your offending storyboard as source code:
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.
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.
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)
}
}
i set all constraints there is no probmem. But when i re-open the project all widths and heights values changes to 1000. There is only one view has problem. I deleted it then created again but still has same problem. How can i solve this?
Apparently this is a bug in Xcode 8.
Related Question: xcode-8-storyboard-warnings-for-navigation-bar-width
A possible solution presented in that related question is to change the Simulated Metrics size from Fixed to Freeform.
Also, here some open threads about common problems:
https://forums.developer.apple.com/thread/62929
https://forums.developer.apple.com/thread/63108
https://forums.developer.apple.com/thread/63144
https://forums.developer.apple.com/thread/61797
https://forums.developer.apple.com/thread/63029
https://forums.developer.apple.com/thread/63068
https://forums.developer.apple.com/thread/63067
https://forums.developer.apple.com/thread/63067
https://forums.developer.apple.com/thread/62821
https://forums.developer.apple.com/thread/62882
https://forums.developer.apple.com/thread/62321
I've got a few buttons with text inside. If i run the app on an iOS 10 device, it works and shows the text fine. But running the app on iOS 9 the text inside the button is like "squashed" or "compressed"(the text on version 9 is missing the top and bottom part of the text). I'm not sure why this is happening, I've tried messing around with the hugging and compression settings on the UI Builder, but this hasn't really fixed the problem.
Not sure why it works on 10 but not on 9....The image above shows what the text looks like on iOS 9 ONLY!
I'm just seeing if this is happening with anyone else? or if anyone knows how to solve this problem?
I appreciate any help given! Thanks in advance!
You have to use "adjustsFontSizeToFitWidth" property of titleLabel of your button
Example:
myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
There are a few possibilities:
The height of the button during runtime could be wrong. Try setting a border to the button, run and observe the button outline to see if the height is correct.
myButton.layer.borderColor = UIColor.black.cgColor
myButton.layer.borderWidth = 1
If the height is wrong, it means the constraints could be incorrectly set up.
Another possibility might be contentEdgeInsets, titleEdgeInsets properties of the button having larger than intended top and bottom values.
In storyboard , I am seeing a lot of yellow warning. Upon clicking the yellow warning , I get like update frame or update constraints. In the console it throws auto-layout warnings too. I just want to know whether it will crash my app because of this.enter image description here
Yellow warnings and auto-layout warnings in console are not related.
Yellow warnings means that what you see in IB is not what you will get at runtime according to current constraints. If you want to see what you will get you should click yellow warning and press "update frame". If you want to get at runtime what you currently see in IB you should press yellow warning and select "update constraint".
Runtime warnings in console means some constraints conflict at runtime. You should analyse the warning message to find what is the issue.
Most of the time it will not. But I suggest you to fix them all.
why not update all the frames, the difference Xcode complains about is not much, and NO it wont crash your application, BUT Xcode complains as there might be situations where your constraints wont work as per you set them.
Your Application will not crash weather it is a Yellow one or a Red one .
Xcode only means that the constrains you have kept may not work properly in different modes and resolutions .
You can simply fix it by simply clicking on update constraints,but result may not be what you expected.
So click on yellow arrow and read suggestion by xcode.
I opened an existing iOS project with Xcode6 beta6, and Xcode lists the following warning for both Storyboard and Xib files:
Automatic Preferred Max Layout Width is not available on iOS versions
prior to 8.0
I tried addressing the warning by setting the width as explicit like below:
Yet this didn't resolve the warnings. How can they be removed?
Update 3:
This warning can also be triggered by labels that have numberOfLines set to anything but 1 if your deployment target is set to 7.1. This is completely reproducible with new single-view project.
Steps to Reproduce:
Create a new single-view, objective-c project
Set the Deployment Target to 7.1
Open the project's storyboard
Drop a label onto the provided view controller
Set the numberOfLines for that label to 2.
Compile
I've filed the following radar:
rdar://problem/18700567
Update 2:
Unfortunately, this is a thing again in the release version of Xcode 6. Note that you can, for the most part, manually edit your storyboard/xib to fix the problem. Per Charles A. in the comments below:
It's worth mentioning that you can pretty easily accidentally
introduce this warning, and the warning itself doesn't help in finding
the label that is the culprit. This is unfortunate in a complex
storyboard. You can open the storyboard as a source file and search
with the regex <label(?!.*preferredMaxLayoutWidth) to find labels that
omit a preferredMaxLayoutWidth attribute/value. If you add in
preferredMaxLayoutWidth="0" on such lines, it is the same as marking
explicit and setting the value 0.
Update 1:
This bug has now been fixed in Xcode 6 GM.
Original Answer
This is a bug in Xcode6-Beta6 and XCode6-Beta7 and can be safely ignored for now.
An Apple engineer in the Apple Developer forums had this to say about the bug:
Preferred max layout width is an auto layout property on UILabel that
allows it to automatically grow vertically to fit its content.
Versions of Xcode prior to 6.0 would set preferredMaxLayoutWidth for
multiline labels to the current bounds size at design time. You would
need to manually update preferredMaxLayoutWidth at runtime if your
horizontal layout changed.
iOS 8 added support for automatically computing
preferredMaxLayoutWidth at runtime, which makes creating multiline
labels even easier. This setting is not backwards compatible with iOS
7. To support both iOS 7 and iOS 8, Xcode 6 allows you to pick either "Automatic" or "Explicit" for preferredMaxLayoutWidth in the size
inspector. You should:
Pick "Automatic" if targeting iOS 8 for the best experience. Pick
"Explicit" if targeting < iOS 8. You can then enter the value of
preferredMaxLayoutWidth you would like set. Enabling "Explicit"
defaults to the current bounds size at the time you checked the box.
The warning will appear if (1) you're using auto layout, (2)
"Automatic" is set for a multiline label [you can check this in the
size inspector for the label], and (3) your deployment target < iOS 8.
It seems the bug is that this warning appears for non-autolayout
documents. If you are seeing this warning and not using auto layout
you can ignore the warning.
Alternately, you can work around the issue by using the file inspector on the storyboard or xib in question and change "Builds for" to "Builds for iOS 8.0 and Later"
To Find the problem label(s) in a large storyboard, follow my steps below.
In xCode's Issue Navigator right click on the error and select "Reveal In Log". (Note: #Sam suggests below, look in xCode's report navigator. Also #Rivera notes in the comments that "As of Xcode 6.1.1, clicking on the warning will automatically open and highlight the conflicting label". I haven't tested this).
This will show the error with a code at the end of your storyboard file. Copy the value after .storyboard
Next, reveal your storyboard as source file.
Search. You should be able to tell what label it is from here quite easily by looking at the content.
Once you find the label the solution that worked for me was to set the "preferred width" to 0.
BTW, you can always quickly get the id of an interface item by selecting the item and looking under the identify inspector. Very handy.
You can fix this issue without opening the storyboard as a source.
This warning is triggered by UILabels if numberOfLines !=1 and deployment target is < 8.0
HOW TO FIND IT?
Go to Issue Navigator (CMD+8) and Select latest built with the warning
Locate the warning(s) (search for "Automatic Preferred Max Layout") and press expand button on the right
Find the Object ID of the UILabel
Open the Storyboard and SEARCH (CMD+f) for the object. It will SELECT AND HIGHLIGHT the UILabel
Set Preferred Width = 0 "Explicit" as others suggested
Solution it's quite simple
Just enable Builds for iOS 8 and Later
Now my Xcode version is 6.1. But I got this warning too. it annoys me a lot . after search again and again.I found the solution.
Reason:You must have set your UILabel Lines > 1 in your Storyboard.
Solution: set your UILabel Lines attribute to 1 in Storyboard. restart your Xcode. It works for me, hope it can help more people.
If you really need to show your words more than 1 line. you should do it in the code.
//the words will show in UILabel
NSString *testString = #"Today I wanna set the line to multiple lines. bla bla ...... Today I wanna set the line to multiple lines. bla bla ......"
[self.UserNameLabel setNumberOfLines:0];
self.UserNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
UIFont *font = [UIFont systemFontOfSize:12];
//Here I set the Label max width to 200, height to 60
CGSize size = CGSizeMake(200, 60);
CGRect labelRect = [testString boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName] context:nil];
self.UserNameLabel.frame = CGRectMake(self.UserNameLabel.frame.origin.x, self.UserNameLabel.frame.origin.y, labelRect.size.width, labelRect.size.height);
self.UserNameLabel.text = testString;
To summarize, for me following the two instructions above to change any instances where numberOfLines = 0 to 1 or greater, and manually adding preferredMaxLayoutWidth="0" to each instance of a label inside the storyboard source fixed all of my warnings.
Since I don't have a 50 reputation Stackoverflow wont let me comment on the second best answer. Found another trick for finding the culprit label in the Storyboard.
So once you know the id of the label, open your storyboard in a seperate tab with view controllers displayed and just do command F and command V and will take you straight to that label :)
I got it working by selecting the original layout I had in the W / H selection. Storyboard is working as expected and the error is gone.
Be also sure that you are developing for iOS 8.0. Check that from the project's general settings.
This is where you should press.
I had this issue and was able to fix it by adding constraints to determine the max with for a label.
When dropping a multiline label in there is not constraint set to enforce the width inside the parent view. This is where the new PreferredMaxWidth comes into play. On iOS 7 and earlier you have to define the max width yourself. I simply added a 10px constraint to the left and right hand side of the label.
You can also add a <= width constraint which also fixes the issue.
So this is not actually a bug, you simply have to define the max width yourself. The explicit option mention in other answer will also work as you are setting this width value however you will have to modify this value if you want the max width to change based on the parent width (as you have explicitly set the width).
My above solution ensures the width is always maintained no matter how big the parent view is.
For some reason, even if changing the iOS Deployment Target to 8.0 or higher, the Xib files don't adopt that change and remain with the previous settings in the File inspector
Therefore, you should change it manually for each Xib
Once done, the warning will disappear :-)