UILabel lineBreakMode clip doesn't clip text - iphone

So I have a UILabel and I've set it's line break mode to clip, but I don't see the ... at the end, instead it just truncates/cut the text at the point where it overflows. Is there any other part of the code that I need to set?
Here's how I am doing it:
[self.newsFeedHeadingTitle_ setLineBreakMode:UILineBreakModeClip];

Set it to "UILineBreakModeTailTruncation" if you want the dots at the end of the string.

You also have to set the number of lines the UILabel is allowed to have. Like this [myLabel setNumberOfLines:x] where x is the number of lines you want to have. If you set x to zero , the label can have as many lines as it needs. By default, that value it's 1 so that is why your label does not break the text into multiple lines.
Hope this helps.
Cheers!

If you're using plain NSString-objects on a UILabel, myLabel.lineBreakMode = NSLineBreakByTruncatingTail; should work.
If you are using NSAttributedString-objects with a NSParagraphStyle, use myParagraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
Setting the linebreak-mode of the paragraph-style worked for me.

Related

AttributedString Not working with UILabel

I have the below code, that runs in viewDidLoad.
let text = "\n \t What is a Call?"
let attributedText = NSMutableAttributedString(string: text, attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 30)])
textLabel.attributedText = attributedText
When it runs, nothing gets set in the label. However, if I set it like this
textLabel.text = text
I see the attributed text? Why doesn't the previous line of code work?
I tried adding your code to a completely clean project and found two potential issues. Maybe you have thought of both of them but I couldn't read that from your question so here goes :)
Number of Lines
It is a bit tricky but when you add a \n in your text, that also means that if you haven't explicitly told your UILabel to take that into consideration, it will only show the first line...which is empty in your case :)
So, try adding
textLabel.numberOfLines = 0
to tell your UILabel to use as many lines as is needed for the text.
Size of Your Label
I don't know how you've set up your label, but it could be that the size reserved for the label is too small for all of it to be shown on the screen. You can use the visual debugger to examine the view hierarchy and see if that can give you any clues.
If I set numberOfLines to 0 and added constraints to the textLabel so it had sufficient space, I was able to see "What is a Call?" in glorious 30 point bold system font on my view so...you're close :)

Get Text of UILabel with lineBreakMode

I want to get the visible Text of UILabel that received lineBreakMode and numberOflines in Nib file.
Or NSarray of the text (visible and not visible), each row is row in label..
Can Someone help me?
Thank you..
Edit:
In xcode I have UILablel, I create label in a nib file.
In the UILabel properties, I determine the number of line and also LineBreakMode.
Example: In the phonebook there is 1 number of line, and I have a very long name so I just see the begining of the name with 3 dots after(if the name in the phonebook is longer then the frame of the label) I think this is LineBreakMode:trunk property.
the name is:Rebecca. so we will see Reb...
If it's LineBreakMode:wrap so the 3 dots will not apper but we will see less from the name, etc.
What I need is to know what is the visible text.
if the text is Rebecca, but on screen I see Reb... so I need only Reb..., and not Rebecca.
if it's not trunc, so I need Reb without the 3 dots, and etc.
According to the LineBreakMode property and number of line, I just need to know the visible text that is on screen.
Hope it's more clear now..

How to remove the last empty line of UITextView?

For some reason, UITextView produces an empty line at the end which causes it to be scrollable for nonsense when the text actually fits perfectly into the bounds.
I figured out that this additional space added to the bottom of the text in the contentView of UITextView is almost exactly the font size. So it is an additional line of text.
I want to remove that line so the UITextView is not scrollable when there is no reason to scroll.
editable is set to NO.
I tried setting the contentSize property with a reduced height but this has no effect.
The string has no whitespace or return character at the end. It comes from UITextView. Tested with a lot of different strings.
You can try altering the contentInset property and set the bottom inset to -10. I personally think it would be a hack but it worked when I tested it so just check what the correct inset would be.
textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whiteSpaceAndNewLineCharacterSet]];

How to format different characters in a UILabel's string differently?

I have a UILabel with a dynamic string as the text property. If I always want the first word to be underlined, do I need to separate labels and then try to line them up correctly? Or could I subclass UILabel to have it do this?
Use a UIWebView and render the text as HTML.
I ended up using the textRectForBounds:limitedToNumberOfLines: to find the dynamic start point of the word (minus some x coordinate pixels), and then took away the first letter of the uilabel with stringByReplacingCharactersInRange:withString:, and then added another uilabel with the beginning letter of the original label, just with different font.

How to make multi-line text on the iPhone?

Would I use a UILabel for that? Or is there something better?
It depends on what you want to achieve. If you just want a multi-line label, then you can use UILabel with the numberOfLines parameter set to something other than 1 (set it to zero if you don't care how many lines are used). If you need to let the user edit the text, then a UITextView is the way forward. Line breaks are indicated using the \n character, not the /n sequence as Emil incorrectly wrote.
You can use a UITextView, and write \n where you want the new lines.
Hey!\nHow are you?\n\n\nYOU: I am fine.\nME: That's great! will display:
Hey!
How are you?
YOU: I am fine
ME: That's great!