I have multi-line non-HTML text (with newlines). Need to output it inside ScrollView or just UIView.
I can't output it as UITextView: can't find how to resize UITextView to the size of text and/or disable scroll in it.
Should I output text to Label?
Or there's something more proper for that?
Thanks.
Try using a UILabel, then set the lineBreakMode property to UILineBreakModeWordWrap, and the numberOfLines property to zero (unlimited lines).
Depending on the style of text you're using, you might try stripping out the newlines so the result looks better.
Related
I want to insert a text inside the area which one surrounded by UIEdgeInsets in UITextView.
Take a look at the following image
Here '1'(surrounded by border for easier understanding) --> The text which one I want to insert inside the UIEdgeInsets.
Here 'one' is the content inside UITextView.
Can I do it? If it is, give me an example.
I have a UITextField that is 300px width and 270px height. When I want to edit it, the cursor goes automatically in the middle and I can only write on the middle line.
How can I set this UITextField to have severals lines and a cursor starting at the top-left ?
Simple answer, just use UITextView instead.
UITextfield is designed for single line only, If you want to enter multi line text than use UITextView instead and set its editable property to YES than it would behave like textfield!
[myTextView setEditable:YES];
Note: You can also set it via Interface Builder, select the "editable" box & It will be multiline by default.
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]];
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.
I've been using uiLabels to put text in the cells of tableviews. I want to now use paragraph text that carriage returns to the next line instead of going out of the boundaries of the table cell. Would I do this by manipulating a uiLabel or would I use a different control all together like a text view.
Also is there any project examples out there that implement this?
Thanks,
Joe
Simplest way is to use a UILabel and set the number of lines in IB to > 1 then set the line break to "Word Wrap."
Another way is to use a UITextView, load the data and set it to 'disabled' so it can't be edited.
Finally, you can always go the UIWebView route and load it with formatted HTML, complete with line breaks, etc. Pretty heavy, but most flexible.
The simplest approach is to use a UILabel, probably. The only alternative would be to make a custom UIView subclass that draws the text directly, but that will give you marginal benefit.