56231

iOS Objective-C wrap text of UITextField in UIAlertView and dynamically adjust height based on conte

Question:

I have a UIAlertView with the alertViewStyle of UIAlertViewStylePlainTextInput. I'm trying to find a way to make the UITextField of the UIAlertView adjust its height and wrap its text based on its content as the user types.

To be quite honest, I haven't the slightest clue how to do this.

Here is some of my code:

-(void)updateTicket:(id)sender { UIButton *sndr = (UIButton*)sender; int index = sndr.tag; UIAlertView *alert = [[UIAlertView alloc] init]; [alert setTag:-7]; [alert setDelegate:self]; [alert setTitle:[NSString stringWithFormat:@"Update Ticket #%i", [ticketIDs[index] intValue]]]; alert.alertViewStyle = UIAlertViewStylePlainTextInput; [alert textFieldAtIndex:0].placeholder = @"Note"; [alert textFieldAtIndex:0].tag = index; [alert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences; [alert textFieldAtIndex:0].autocorrectionType = UITextAutocorrectionTypeYes; [alert textFieldAtIndex:0].autoresizingMask = UIViewAutoresizingFlexibleHeight; [alert addButtonWithTitle:@"Cancel"]; [alert addButtonWithTitle:@"OK"]; [alert setCancelButtonIndex:0]; [alert show]; }

Answer1:

It is not possible to have a UITextField with multiple lines and dynamic height.

To achieve this please create a custom alert and add a UITextView as UITextViewcan have multiple lines. Override the <em>textViewDidChange:</em> and calculate the size of the text in the textview with <em>sizeWithFont:constrainedToSize:lineBreakMode:</em>. It will return the CGSize based on the height adjust the height of the UITextView and the alert.

Thanks

Recommend

  • Angle based orientation ns2 not working
  • Multiple or malformed newlines found in additional_header
  • Loading huge Text file in UITextview crashes
  • adding zeros in objective-c string formats
  • Customizing NSLog Function on iPhone
  • using AVSystemController in iPhone App
  • Unable to add the file iOS application bundle
  • Display a .pdf in an iOS app without downloading it from the internet
  • How do I include superscripts in NSString?
  • bundle sqlite database with app and stringByAppendingPathComponent error
  • Objective-C – access extern const with a string containing its name? [duplicate]
  • Post comment to WordPress Blog from iPhone programmatically
  • iOS Date formatting
  • Get UILabel out of UIButton
  • Aligning image on right side of title on UIButton with imageEdgeInsets and titleEdgeInsets
  • What is this iOS exception with NSCFType?
  • how to solve invalid conversion specifier warning in iphone app
  • c# open webrowser in many tab
  • How do I superscript characters in a UIButton?
  • How to Cache Real-time Data?
  • Functions in global context
  • FileReader+canvas image loading problem
  • Get one-time binding to work for ng-if
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Volley JsonObjectRequest send headers in GET Request
  • Importing jscolor library in angular 2
  • Rearranging Cells in UITableView Bug & Saving Changes
  • AT Commands to Send SMS not working in Windows 8.1
  • Compare two NSDates in iPhone
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Proper way to use connect-multiparty with express.js?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to stop GridView from loading again when I press back button?
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Sorting a 2D array using the second column C++
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal