-1

This question is not about UITextView: It's about UITextField.

How do I check if my text would be too long for my UITextField? I need to dynamically change the Height of my UITextField so that it accepts multiple lines. Is this possible or must I use a UITextView for this? I prefer UITextField because of the convenience of a placeholder text.

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199

2 Answers2

1

You can use

sizeWithFont:

of NSString to avaluate the length of a string.

UITextField is not able to show multiple lines. For solutions take a look at

Objective C: How to create a multi-line UITextField?

Claus

Community
  • 1
  • 1
Thallius
  • 2,482
  • 2
  • 18
  • 36
0

Hi just use small trick for this code sample below.

+ (CGFloat)expectedHeightWithData:(MECommentData *)data
{
    @autoreleasepool
    {
        NSString *comment = data.comment;

        UIFont *commentSizeFont = [UIFont fontWithName:@"Miso-Bold" size: 15.0];
        CGSize commentSize = [NSString sizeWithFont:commentSizeFont width:225 heitght:3000 text:comment];

        return ceilf(commentSize.height);
    }

}
Oleg Gordiichuk
  • 15,240
  • 7
  • 60
  • 100