UILabel AutoShrink property in not working in ios 7 - ios

I added Autoshrink Property of my label from nib file as follow;
It is working good in ios6 but not effected in ios7.
ios6:
ios7
Why this happen? I am using numberoflines=2
Help to solve this
Thank you

Yes that is because you are using
numberOfLines = 2
that means your label will be of two lines, so its auto adjusting the size accordingly as your label will be of 2 lines,
set background color of the Label to get to know about the label dimension.
EDIT -
If you want your labeltext to fit someother Superview element accordingly and have thinking that your label can have a text too long, then set numberOfLines = 0.
Basically numberOfLines means the Maximum line breaks the text of the label can have
Set your FONT to a lower value - 14,13 (judging by your previous one that is what i am sensing)
Set your Label to a fixed width, so that you know that a nextLine would appear after that width,
Set Number of lines to 0

Related

iOS10 UILabel use NSLineBreakByCharWrapping has half character ,how to fix it?

this is UILabel show half character!!!
this is UILabel attribute!!!
The Linebreaking is only working if the label have the chance to break the line. But with "Lines" set to 1, there is no chance.
Set the Lines to 0 (auto) or at least to 2 and it will work.
just set auto shrink to minimum font scale from storyboard so it will automatically set the size of font according to the label width or programmatically set [self.yourlablename sizToFit]

UILabel text gets truncated with large font size

The text inside my UILabel in Interface Builder is being truncated when the text is a large font size. The UILabel does scroll vertically when the characters exceed the viewport size, but at one point the text is simply truncated. Can anyone advise?
The element hierarchy is: Scroll View > View > UILabel
UILabel AutoLayout properties are set to:
Lines: 0
Line Break: Word Wrap
Autoshrink: Fixed Font Size
I would prefer to keep everything in AutoLayout rather than set the properties programmatically.
You are set the property of Label. So that according to device its set font size is auto.
Autoshrink : Minimum Font scale
Scale : 0.7
You can use both **Minimum font Size** &&Minimum font Scale`

Attributed label with custom line height cropping text on top

I need to decrease line spacing on interface builder using attributed text, and changing the line height multiplier it works as desired, but the text is being cropped on top.
I already tried to set the lineSpacing with NSMutableParagraphStyle by code but did not worked or happened the same thing.
There is a way to fix the alignment or setting the correctly the line spacing?
So it isn't a matter of spacing, but more likely constraints. Perhaps your baseline setting is set to none, in which case try changing it to 'Align Centers'.

Swift: UILabel how to show all text

I am very new to Swift and I don't know how to make my UILabel show all text.
Here is how my label looks like in my storyboard:
As you see, part of the text is omitted. I can show all the text by dragging the UILabel to resize. However, during the runtime, if the text is set dynamically, how can I resize the label so that it can show more all of the text?
I tried UILabel.sizeToFit() but that doesn't seem to change anything.
you can do this by setting numberOfLines to 0
Example
myLabel.text = "whatever"
myLabel.numberOfLines = 0
myLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
And you have so set frame according to it
Refer : to this link
YourUILabel.sizeToFit() is right but that is not all of it..
You need to set the number of lines and the kind of line break before calling .sizeToFit()..
YourUILabel.numberOfLines equal to 0 for unlimited number of
lines...
YourUILabel.lineBreakMode equal to NSLineBreakMode dot(.)
ByWordWrapping for example..
If you are not resizing the UILabel frame using autolayout you can change the Autoshrink option by selecting your label from the storyboard and adjust this option on the inspector pane.
.
Why do it the old way.. Let's use autolayout. If you haven't used it yet. Lets begin - Steps :
Create a UIlabel and set it's width to any amount you want it on screen.
Select the label go to Editor menu -> Pin and one by one pin Leading Trailing and Top space to Superview (not the bottom one).
Since you have fixed width and you have dynamic height so also pin Width.
Go to Attribute inspector tab and set lines to 0 (means unlimited).
Go To size inspector and set Content Hugging priority(250/251) to low and Content Resistance priority to high (say - 750).
And you are done.!!(not a single line of code)
You first have to calculate the Height of label according to the length of the Text you want to set and then accordingly increase the number of lines
as
yourLabel.numberOfLines = "Your calculation number"
and then Set the Frame of the Label according to the Height calculated
and
if you cannot calculate the height of the Label then i would say use the TextView it will automatically add a scroll to the text and you can view all the text.

Multiline UILabel with auto layout does not work

I'm trying to set constraints to get a multiline label in a static table view cell, but apparently this does not work for me, the label is still in one single line. I've set the numberOfLines property to 0 and also the height constraint to greater than or equal. And I'm setting the height for the cell correctly in tableView:heightForRowAtIndexPath. Please have a look at my screenshot to see the settings in IB.
In the comments above you mentioned you're not currently setting preferredMaxLayoutWidth. This property tells your label that it should lay out its text over the width of that property's value. In UILabel.h:
If nonzero, this is used when determining -intrinsicContentSize for multiline labels
In other words, if you don't set that, the label's intrinsic content size is whatever width the label needs to draw its text. If you set this property to the label's bounds, it will start drawing on the next line (or else it will cut the text off if numberOfLines is 0).
In your case, I would probably do that in tableView:willDisplayCell:forRowAtIndexPath:.
You can set the preferredMaxLayoutWidth in code, but when designing your user interface in storyboard, you still see a long one-line label that gets cut off at the edges. An alternative is to manually insert line breaks anywhere in your text right within the storyboard using Option-Return. You then just set the number of lines to more than your text will fit. Then select your label, hit Cmd-=. This will calculate the intrinsic content size for your label with the line breaks exactly where you want them to be.
Theoretically, I think setting the preferredMaxLayoutWidth is the more correct way to go about this, especially using Autolayout. However, I found it more practical to use the method I described above because it lets you see the layout at design time right in the storyboard, and you have total control of your line breaks. This usually works better for labels with text that don't change often. If you are dynamically changing the label text, setting preferredMaxLayoutWidth is the preferred way.

Resources