Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made herehere. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
   
    // Get your text to NSAttributedString 
    NSAttributedString *as = [[NSAttributedString alloc] initWithString:self.notePad.text];

    // Resize UITextView
    self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:as andWidth:kbSize.width)]);
}

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made here. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
   
    // Get your text to NSAttributedString 
    NSAttributedString *as = [[NSAttributedString alloc] initWithString:self.notePad.text];

    // Resize UITextView
    self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:as andWidth:kbSize.width)]);
}

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made here. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
   
    // Get your text to NSAttributedString 
    NSAttributedString *as = [[NSAttributedString alloc] initWithString:self.notePad.text];

    // Resize UITextView
    self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:as andWidth:kbSize.width)]);
}
text from self.notePad to NSAttributedString
Source Link
Jordan Montel
  • 8.2k
  • 2
  • 37
  • 40

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made here. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
   
    // Get your text to NSAttributedString 
    NSAttributedString *as = [[NSAttributedString alloc] initWithString:self.notePad.text];

    // Resize UITextView
    self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:(NSAttributedString *)self.notePad.textas andWidth:2kbSizekbSize.width)]);
}

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made here. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;


        self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:(NSAttributedString *)self.notePad.text andWidth:2kbSize.width)]);
}

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made here. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
   
    // Get your text to NSAttributedString 
    NSAttributedString *as = [[NSAttributedString alloc] initWithString:self.notePad.text];

    // Resize UITextView
    self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:as andWidth:kbSize.width)]);
}
Source Link
Jordan Montel
  • 8.2k
  • 2
  • 37
  • 40

You need to resize your UITextView when your keyboard appears. So have a look to a previous answer I made here. You need to call the following method to resize your UITextView depending of the width of your keyboard and the text :

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andWidth:(CGFloat)width
{
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Your code using my method :

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;


        self.notePad.frame = CGRectMake(0, 0, CGRectGetWidth(self.notePad.frame), [self textViewHeightForAttributedText:(NSAttributedString *)self.notePad.text andWidth:2kbSize.width)]);
}