V
V
Votetoda2015-03-04 16:08:35
Objective-C
Votetoda, 2015-03-04 16:08:35

How to make textview=contentsize?

Good afternoon, I need to understand how you can bring a textview or let's say a label component its size to the content. I found a lot of materials on this issue, but they all do not work, do not tell me where to find working sources or an example

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
feniksqip, 2015-03-28
@Votetoda

For the label you need:
1) number of lines = 0
2) line transfer (character by character, word by word)
and that's it! works for me - the label is stretched! If you need a code, I'll look for it, write!

A
Alexander, 2015-03-06
@alexyat

I use just such a function,
set the font and width that you will use in the label. And send along with the text. And get the height of the text.

+(CGFloat)sizeForText:(NSString *)text withFont:(UIFont *)font withWidth:(float)width
{
  CGSize constraint = CGSizeMake(width, 20000.0f);
  CGSize size = [text sizeWithFont:font
           constrainedToSize:constraint 
             lineBreakMode:NSLineBreakByWordWrapping];
  return size.height;
}

S
smanioso, 2015-03-04
@smanioso

For UILabel, you can try using the numberOfLines = 0 property:
This property controls the maximum number of lines to use in order to fit the label's text into its bounding rectangle. The default value for this property is 1. To remove any maximum limit, and use as many lines as needed, set the value of this property to 0.
https://developer.apple.com/library/ios/documentat...

P
Petr2008, 2015-03-12
@Petr2008

Fastest autolayout in IB

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question