0
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"HELOOOOOOOO" message:@"write a number of text-lines/paragraph here"
                                                      delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Yes", nil];
       UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 95, 260, 25)];
       [myTextField setBackgroundColor:[UIColor whiteColor]];
       [alert addSubview:myTextField];
       [alert show];

If you look close you will find that the message attribute is quite long. I need this alertview to first display the title, and then my long message, and then the text field and finally the 2 buttons.

But what hapence here, is that since the message is too long, the textfield overlaps with the buttons.

How can i solve this ?

9to5ios
  • 5,319
  • 2
  • 37
  • 65
shajem
  • 2,111
  • 5
  • 22
  • 30

4 Answers4

0

Implement this piece of code in your implementation file.

- (void)willPresentAlertView:(UIAlertView *)alertView
{
alertview.frame = CGRectMake(12, 95, 260, 25); //You can set a frame that suits to your needs
}

This delegate - (void)willPresentAlertView:(UIAlertView *)alertView will invoke before showing the alerview, so it is a better way to set frame to your alertview.

For more informations on aleert views: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/occ/intf/UIAlertViewDelegate

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
0

If this is for iPhone, you really can't. The UIAlertView is not meant to handle input. Extended messages are shown with a scroll view but you really should not add a UITextField to it's view hierarchy (for one, it goes against their design standards and your app MAY get nixed!).

In this situation, it would probably be best to use a new UIViewController to handle showing your content.

Again, the only "actions" that UIAlertView is meant to provide is that of the multiple buttons.

Taylor Dondich
  • 628
  • 4
  • 9
  • But, in appstore when you try to purchase an app, apple pops up a similar UIAlert view with the password textfield. So why is it not right to add it ? or is apple using a view that looks like an alertview ? – shajem Mar 22 '12 at 18:12
  • Well, Apple does have access to a lot more frameworks than we do (like fully running applications in the background), not to mention since they built UIAlertView, they can modify it any way they can. But also, there's a private, undocumented method to put a UITextField in an alert view. – Kevin Low Mar 22 '12 at 19:18
  • @KevinLow so my application is more likely to get rejected if i use the alertview containing an textfield ? – shajem Mar 22 '12 at 23:35
  • Not at all. It's all about how you do it, though. If you subclass UIAlertView and modify the bounds as well as the positions of subviews, then that's fine. If you use a third party library which also does it in this manner, then that's fine as well. It's only if you use the private Apple API will your app get rejected (though the private API is what Apple uses so it's more visually accurate I suppose you could say). – Kevin Low Mar 23 '12 at 14:26
0

Actually, it doesn't matter how long your message is. The alert view will always size so it fits.

One way you can fix this is by adding a bunch of \n at the end of your message string, which is equivalent to putting a line break.

EDIT: If your message is so long that it puts it in a UIScrollView, there's nothing you can really do unless you're fine with major hacking (aka, changing the bounds of the UIAlertView, moving each button down, etc.).

A second way works only on iOS 5 and newer. You can set the UIAlertView's alertStyle property to UIAlertViewStylePlainTextInput which will display an alert view with a text field.

Artem Shmatkov
  • 1,434
  • 5
  • 22
  • 41
Kevin Low
  • 2,672
  • 16
  • 17
  • I have to build this app for both iOS 4 and 5. Isn't there a library that where you could add text fields, and it looks like an alertview ? i can remember that there was one, but can't remember the name – shajem Mar 22 '12 at 18:21
  • I actually have no idea if there are any third party code. There's private api if you're not looking for AppStore approval. – Kevin Low Mar 22 '12 at 21:24
0

Use newline or line break character \n for this:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertView"message:@"\nhello:.................... \nwrite here.................. \nwrite here....................." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];

see output alert image

Check this blog post for more help

Flexo
  • 87,323
  • 22
  • 191
  • 272
9to5ios
  • 5,319
  • 2
  • 37
  • 65