Preferred Width is missing in xcode 5.1.1 - ios

I'm trying to make something like in this guide http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout,
but can't find property for UILabel named Preferred Width
Is it bug or have i done something wrong?

If you can't find it in that version of Xcode, you can do it in code
[label setPreferredMaxLayoutWidth:200.0];

Related

Xcode custom fonts not showing up in Storyboard

I added my two fonts to my project folder:
I added them to info.plist:
I can not see them in my custom font list in the storyboard:
What have i done wrong?
I know this is a pretty old question, but I ran into the same issue. And the above tips didn't work for me. Apart from the standard checks (present in bundle, restarting XCode, the thing that fixed my issue was that my label text type was marked as "Plain" and hence some fonts were not showing in the dropdown in the Storyboard. As soon as I changed the text type to "Attributed", all the fonts appeared in the dropdown.
Hope this'll help someone stuck with the same issue.
This drop-down box shows the system-wide installed fonts. So you need to install your custom font on your system first so it's appearing in that drop-down box. You can do that by double-clicking it, the FontBook.app opens and asks you whether you want to install the font.
This was a huge headache for me but I simply fixed it by:
I fixed the issue by restarting my Mac.
Then restarting Xcode.
I Installed the font in the system as per DarkDust solution and i am able to see the font in attributed type.
Then i changed the type to plain and i able to see the Custom font in the font types drop down.
Had the same problem but this SO answer by user Saranjith solved it while the other solutions in this thread didn't: Xcode 8 custom font doesn't show up in interface builder
Basically in Font Book select "Computer Fonts" and then hit the + button and re add the Fonts.
This is happened to me after moving to Xcode 11 in Catalina from Xcode 10 in Mojave.
Well, silly mistake on my part, but I didn't realize my font was named something way different from the file name.
Double-clicking the actual font file opened it in the font book, and that showed the actual font name. It was in the dropdown all along.
I solved my problem when i used font name. Do not use file name. I was used like this [UIFont fontWithName:#"appFont" size:17] but it is wrong.
Upload your font file to https://fontdrop.info/ and use the name
My font file name is appFont.ttf but when i uploaded i saw Roboto Regular.
[UIFont fontWithName:#"Roboto Regular" size:17]
Sometime I go to another file and come back, then my custom fonts are arrived. I think this is an issue of Xcode and will be solved in following version.
In my case I just turn the text from plain to attributed then turn it back again to plain then it showed up., hope this help anyone.
I ran into the same issue and fixed with below steps
Closed storyboard
Cleared derived data
Cleaned the project and open the story board
If this is not working then restart the Xcode.
Thanks
For me it was case sensitive issue with the font file name. Not sure if it's always for this reason...
In my case my fonts were in woff2 formats. Although woff2 is supported in iOS, the fonts don't appear or get rendered in Storyboards.
If Xcode showed your custom font before but stopped to do it at some moment, try to readd font files to your project. It solved the problem for me. Other answers weren't helpful.

Xcode 6 : Changing the Font for a Size Class

I'm trying to setup different fonts or some sort of font scaling in my Size Classes in Xcode 6 as listed by this page:
https://developer.apple.com/library/prerelease/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/ChangingtheFontforaSizeClass.html#//apple_ref/doc/uid/TP40014436-CH12-SW1
The problem is I can't seem to get past Step #3 which says:
I do not see a + button.
Am I missing something or is the documentation wrong?
Thanks
It's very tiny (at least on Mavericks). Took me a moment to find it too.
Maybe this will help?

Multiline label in iOS8

I have updated my device iOS to iOS 8 and now multiline label is not working. Its displaying very weird screen shot attached.
So please can you suggest me the solution.
I already set Number of lines =0 and it was working perfect in ios 7.
Not using Autolayout and story board.
This code help you.It works fine me.Edit your code according to need
UILabel *problem = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 200, 100)];
problem.lineBreakMode=NSLineBreakByWordWrapping;
problem.text=#"Please use this code it may help you it works fine for me";
problem.numberOfLines=0;
[self.view addSubview:problem];
Strangely enough, this fix doesn't work if you don't use all of it:
Set the line break mode to word wrapping (if that's the affect you want).
Set the number of lines to 0 (I had it set to 2 and it still didn't work).
Not sure if something changed here with the introduction with iOS 8 but my previous code (just setting the number of lines to 2) was working great on iOS 7.
Anyone else face a similar issue?
Do you use a custom font?Try changing the font.

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

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 :-)

Minimum Font Size deprecated on ios version 6.0

I just upgraded to xcode 4.5 with iOS 6.0 and it's highlighting a warning on all the UILabels in my XIB files saying "minimum font size deprecated on ios version 6.0". Does anyone know what this is referring to and how to fix it?
Update:
image is no more available (was at https://skitch.com/hahmadi82/eyk51/cloud)
minimumFontSize property of the UILabel is deprecated from iOS 6.0 onwards.
An Alternative to the minimumFontSize is minimumScaleFactor. If you assign minimumFontSize/defaultFontSize to minimumScaleFactor, it works in the same way as minimumFontSize.
The Code is as follows - For Example the font size is 30.0 and if you want the minimum font size to be 12.0
YOURLABEL.font= [UIFont fontWithName:#"FONT_NAME" size:30.0];
[YOURLABEL setMinimumScaleFactor:12.0/[UIFont labelFontSize]];
Use minimumScaleFactor instead...
Link
Quick fix...Here minimum font size to be 8.0
CGFloat size = textLabel.font.pointSize;// font size of label text
[textLabel setMinimumScaleFactor:8.0/size];
I am answering very late, but might help any other.
As every one knows that setMinimumFontSize has been deprecated, so other method replacing setMinimumFontSize is setAdjustFontToFitWidth which takes BOOL
e.g
[yourLabel setAdjustsFontSizeToFitWidth:YES];
//or
yourLabel.adjustsFontSizeToFitWidth = YES;
For Swift use the following:
//set the number (ex. 8 to your desired minimum font size)
myLabel!.minimumScaleFactor = 8/myLabel!.font.pointSize;`
Works like a charm!
I had similar problem. Quick fix is to use MinimumScaleFactor property of UILabel.
Go into finder and find the .storyboard file or your .xib and open with TextEdit. Use find to locate the string "autoshrinkMode" and replace the value "minimumFontSize" to "minimumFontScale"
Odd that the conversion wasn't written in the update scripts...
Also credit to #Rob in the comments above for stating the same answer. He should receive credit for this one.
You can use minimum scale factor over there or drag a lable and set autoshrik-> minimum font.
Maybe this can help you.
Yes minumumFontSize is deprecated.
Use following minimumScaleFactor:-
Obj.minimumScaleFactor= (floatValue);

Resources