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

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]

Related

UILabel height depending on font size

I am using a UILabel in a UITableViewCell to display a title. Normally the text is not too long and therefore the font size can be large. Notice how the text fills the height of theUILabel like normal.
However, when there is a larger title, I want the UILabel height to reduce to accommodate the smaller font size and not leave a blank gap in its place. Currently, my configuration produces this effect.
I am using constraints in my storyboard and have deliberately not set a fixed height constraint. Here are the relevant constraints added:
I may have made a rookie error in my configuration as I can't remember this effect happening before, but it is giving me real headaches (and a bad looking UI).
When UILabel is set to auto-adjust font size to fit, it does NOT auto-adjust the height of itself.
You have a couple options:
set Baseline to Align Centers, and just accept that you will have top and bottom padding
use code to calculate the "scaled font size" and update the font size of the label
Remove either the Top Space or Bottom Space constraints (depending on where you want the label to be anchored).
This will cause the label to automatically use fit itself to the text size.
Try this and see, it should work according to your need:
Set Top and Bottom constraints attribute Greater Than or Equal To and add horizontal center (Alight Center Y to superview) and show in this image.

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.

UILabel AutoShrink property in not working in ios 7

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

Resources