Reputation: 874
I have a question , I would multiple UITextField
in my iOS application, but since it's not possible i use editable UITextView
, where i set my "placeholder" and my property, this is the code:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSString *presentText = self.textFieldObject.text;
if (![presentText isEqualToString:@"Message..."] && presentText != nil)
{
self.textFieldObject.textColor = [UIColor blackColor];
}
else
{
self.textFieldObject.text = @"";
self.textFieldObject.textColor = [UIColor blackColor];
}
return YES;
}
-(void)textViewDidChange:(UITextView *)textView
{
if(self.textFieldObject.text.length == 0)
{
self.textFieldObject.textColor = [UIColor colorWithRed:215.0/255.0 green:215.0/255.0 blue:215.0/255.0 alpha:1.0];
self.textFieldObject.text = @"Message...";
[self.textFieldObject resignFirstResponder];
}
}
I would that UITextView
increase its hight when I write more text like iOS mail app or Facebook post.
Under and over the UITextView
there are any object so they will should move when hight increase. How can I solve the problem?
Thanks a lot.
Upvotes: 1
Views: 112
Reputation: 1878
First, disable UITextView's scrollable.
Two options:
uncheck Scrolling Enabled in .xib.
[TextView setScrollEnabled:NO];
Create a UITextView and connect it with IBOutlet (TextView). Add a dummy UITextView height constraint with default height, connect it with IBOutlet (TextViewHeightConstraint). When you set your UITextView’s text asynchronously you should calculate the height of UITextView and set UITextView’s height constraint to it.
sample code snippet:
[TextView setText:song.lyrics];
CGSize sizeThatFitsTextView = [TextView sizeThatFits:CGSizeMake(TextView.frame.size.width, MAXFLOAT)];
TextViewHeightConstraint.constant = sizeThatFitsTextView.height;
Upvotes: 1