Get Text of UILabel with lineBreakMode - iphone

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..

Related

Word cutting off between lines in button

I have buttons that can hold multiple lines of text (title). However, occasionally, the words or numbers would cut off between lines. It is also good to note that I am getting the text for the button's title from a Database.
How do I make it so that the word would just go down to the next line?
Here is an example:
Set the button's Line Break mode to "Word Wrap" in your storyboard.
If setup by code, set the lineBreakMode of the button's titleLabel property to .byWordWrapping.

UILabel lineBreakMode clip doesn't clip text

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.

UITableView cell multiline justification

I have seen questions posted on here asking how to left and right align two lumps of text, but how can I neatly left and right justify an entire paragraph inside a multiline cell? (Such as what MS Word etc would do if you click on the justification button so that left and right sides of the text are always aligned).
You can also create a custom cell with label which IBOutlet to this class that can be downloaded on github OHAttributedLabel, then try the code below
cell.label.textAlignment = UITextAlignmentJustify;
Is this what you're looking for?
yourTextLabel.textAlignment = UITextAlignmentCenter;
Along with the frame size that you want for your text label.

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.

iPhone : How to obtain the number of lines entered in textView without consideration of width

In my iPhone app, I have a textview where in the user will input multi-line data.
Now I need a solution where I can get the number of lines.
I need a solution which does not have consideration of width.
I need only number of lines entered by user in textView.
How can I do so?
Since you said "without consideration of width" and not "without consideration of height", this is how you do it:
int numberOfLines = yourUITextView.contentSize.height / yourUITextView.font.lineHeight
The UIFont property lineHeight is new from iOS4.0, for older versions use leading property.
Edit,
this answer applies to text views where there have been automatically inserted line breaks (i.e. the line got to long), if you only want to know the number of manually inserted line breaks, Terentes answer would do it.
To count manually inserted line breaks, this hack should do it:
int numberOfManuallyBreaks = [[yourUITextView componentsSeparatedByString:#"\n"] count];
Have you tried fetching the number of lines by using the numberOfLines property of TextView.
By line you mean when user press the return key on the key board? If so count the \n in it.
Hope that helps.
NSArray *arrayWithLines = [myString componentsSeparatedByString:#"\n"];
NSLog(#"Number of Lines:%#",[arrayWithLines count]);