How to add TextView 320*460 in UIAlertView iPhone - iphone

I am showing EULA at the start with UIAlertView having Accept button. I have successfully followed answer on Problem with opning the page (License agreement page) link.
I just want to show 6 pages of EULA at the start but I am unable to show the full size textview/scrollview having EULA content in Alertview. Can anyone suggest me the proper way. Thanks in advance.

You can make alertView of any size and add custom TextView of any size. Use code snippiest
- (void) doAlertViewWithTextView {
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
alert.title = nil;
alert.message = nil;
alert.delegate = self;
[alert addButtonWithTitle:#"Cancel"];
[alert addButtonWithTitle:nil];
UITextView *textView = [[UITextView alloc] initWithFrame:alert.bounds];
textView.text = #"This is what i am trying to add in alertView.\nHappy New Year Farmers! The new Winter Fantasy Limited Edition Items have arrived! Enchant your orchard with a Icy Peach Tree, and be the first farmer among your friends to have the Frosty Fairy Horse. Don't forget that the Mystery Game has been refreshed with a new Winter Fantasy Animal theme! ";
textView.keyboardAppearance = UIKeyboardAppearanceAlert;
textView.editable = NO;
[alert addSubview:textView];
[textView release];
[alert show];
[alert release];
}
But by making the size of alertView equal to size of whole iPhone screen you will lose cancel button.
Also use this delegate method.
- (void)willPresentAlertView:(UIAlertView *)alertView {
[alertView setFrame:CGRectMake(0, 0, 320, 460)];}

Related

Adding TextView to UIAlertView

when I add textview on alertview, the scollview is shown on top and behind of it the text is drawn,how to overcome this problem. Here is the code
question updated:
If the set textView.editable = NO; it work's fine but in my case i need to type the text in textview.
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 50)];
[textView setText:#"lashdasjh asdasjdas asdlajsdl adsjajadsd aslj daj sdjasdjasjdlasjd as dlasj d"];
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"Type Your Message" message:#"\n\n\n\n\n\n" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Send",nil];
av.alertViewStyle = UIAlertViewStyleDefault;
[av addSubview:textView];
[av show];
Resolved mySelf. Remove the #"\n\n\n\n\n\n" in message and add #"\n\n\n\n\n\n" in title
This doesn't work anymore on IOS7, but using https://github.com/wimagguc/ios-custom-alertview will help you get it done pretty well
replace your code with this code its work fine.
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 100)];
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"Type Your Message" message:#"\n\n\n\n\n" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Send",nil];
av.alertViewStyle = UIAlertViewStyleDefault;
[av addSubview:textView];
[av show];

I want to display UIProgressView on UIAlertView

I want to display UIProgressView on UIAlertView for displaying the processing of uploading of the file. But I have searched too much and also find on that link but sill unable to do that. I don't get idea from this
If anyone know the easiest way to do that then please let me know.
I've had problems doing this, and ended up with this:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[av setValue:progressView forKey:#"accessoryView"];
[av show];
Try this code...
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(20, 20, 200, 15);
pv.progress = 0.5;
[av addSubview:pv];
[av show];
While this doesn't quite answer your question, try MBProgressHud, a third-party control that has this feature built-in. The examples supplied on Github should get you up to speed pretty quickly.
Try this code. Put YES for activity indicator and NO for progressView
- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: #"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}
Why not make use of the alerviewdelegate method
- (void)willPresentAlertView:(UIAlertView *)alertView
The advantage of this is we can see what size the alertview will actually be on screen, as iOS has precomputed this at this point, so no need for magic numbers - or overriding the class which Apple warn against !
And as of iOS7 I remember reading some document from Apple saying not to hard code any frame sizes but to always compute them from the app, or something along those lines ?
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGRect alertRect = alertview.bounds;
UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
// Do what ever you want here to set up the alertview, as you have all the details you need
// Note the status Bar will always be there, haven't found a way of hiding it yet
// Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}
To pull reference to the loading bar in
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Then use
UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);
Remember to have defined
#import <objc/runtime.h>
static char myKey;
At the top of your class declaration
This is create a alert view
UIAlertController* alert=[UIAlertController alertControllerWithTitle:#"Message" message:#"This is test" preferredStyle:UIAlertControllerStyleAlert];
now add textfield
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder=#"Enter Text label";
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.backgroundColor=[UIColor whiteColor];
}];
and added it on view
[self presentViewController:alert animated:YES completion:nil];

UITextView large text in UIAlertView

I have an UIAlertView with UITextView.
on ViewDidAppear I do [textView setText:] with a large text, but the alert shows an empty textView, and only after I touch the textView to scroll, the text appears.
What should I do in order to make the text appear in the textView in the alert, without scrolling it to "refresh" it?
Thanks!
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
av = [[UIAlertView alloc]initWithTitle:#"Terms of Service" message:#"\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:#"Disagree" otherButtonTitles:#"Agree",nil];
UITextView *myTextView = [[UITextView alloc] initWithFrame:CGRectMake(12, 50, 260, 142)];
[myTextView setTextAlignment:UITextAlignmentCenter];
[myTextView setEditable:NO];
myTextView.layer.borderWidth = 2.0f;
myTextView.layer.borderColor = [[UIColor darkGrayColor] CGColor];
myTextView.layer.cornerRadius = 13;
myTextView.clipsToBounds = YES ;
[myTextView setText:#"LONG LONG TEXT"];
[av addSubview:myTextView];
[myTextView release];
[av setTag:1];
[av show];
}
This is because you have initially set message as #"\n\n\n\n\n\n\n" for UIAlertView. Set your UITextView first and then set UIAlertView's message as textView's text.
Add \n characters in place of message in alert view . Then create a UILabel add add to alert view. Like this
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:#"%#\n\n\n", #"Title"] message:#"\n" delegate:self cancelButtonTitle:NEVER_DISPLAY_BUTTON_TEXT otherButtonTitles:nil];
[alert addButtonWithTitle:#"Text"];
[alert addButtonWithTitle:#"Text"];
[alert addButtonWithTitle:#"Text"];
[alert addButtonWithTitle:#"Text"];
[alert show];
newTitle = [[UILabel alloc] initWithFrame:CGRectMake(10,-55,252,230)];
newTitle.numberOfLines = 0;
newTitle.font = [UIFont systemFontOfSize:15];
newTitle.textAlignment = UITextAlignmentCenter;
newTitle.backgroundColor = [UIColor clearColor];
newTitle.textColor = [UIColor whiteColor];
newTitle.text = [NSString stringWithFormat:#"%#",self.message];
[alert addSubview:newTitle];
You might need to adjust size of Uilable to match in your alert view.
Try with this:
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"Terms of Service"
message:[NSString stringWithFormat:#"%# \n\n\n",myTextView.text]
delegate:self
cancelButtonTitle:#"Disagree"
otherButtonTitles:#"Agree",nil
];

Custom alertview showing on top?

I am facing a weird situation. I have a tab bar application,where i am showing a custom alertbox in a particular view.The problem is that the alertbox always display on top rather than middle of screen.
I am currently using Xcode 3.2.5 & build it on iPhone simulator 4.2
Edit
-(void)createAlertbox{
alertView = [[UIAlertView alloc] init];
[alertView setDelegate:self];
[alertView setTag:1];
[alertView setTitle:#"sample"];
[alertView setMessage:#" "];
[alertView addButtonWithTitle:#"Enter"];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0,60.0);
[alertView setTransform: moveUp];
ageTextField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0,25.0)];
[ageTextField setBackgroundColor:[UIColor whiteColor]];
[ageTextField setPlaceholder:#"Enter your Current Age"];
ageTextField.keyboardType=UIKeyboardTypeNumberPad;
ageTextField.delegate=self;
[alertView addSubview:ageTextField];
[alertView show];
[alertView release];
[ageTextField release];
}
I don't know why phix23 did't put that comment as an answer!
It's because of the transform :
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0,60.0);
[alertView setTransform: moveUp];
You're telling the ui alert view to be 60px higher than it would otherwise be. Delete these lines and I bet it's in the center again.
Where did you get your code from - I'm assuming that because you didn't know what the transform did you have cut-and-pasted it from somewhere?

TextField Covering UIAlertView's Button

I am using a UIAlertView with three buttons: "Dismiss", "Submit Score" and #"View Leaderboard". The UIAlertView also contains a UITextField called username. At the moment the UITextField "username" is covering one of the buttons in the UIAlertView. I just wanted to know how I could stop the UITextField from covering one of the buttons, i.e move the buttons down.
Here is an image of what is happening:
screenshot http://img684.imageshack.us/img684/3055/screenshot20110108at191.png
And here is my code:
[username setBackgroundColor:[UIColor whiteColor]];
[username setBorderStyle:UITextBorderStyleRoundRect];
username.backgroundColor = [UIColor clearColor];
username.returnKeyType = UIReturnKeyDone;
username.keyboardAppearance = UIKeyboardAppearanceAlert;
username.placeholder = #"Enter your name here";
username = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
username.borderStyle = UITextBorderStyleRoundedRect;
[username resignFirstResponder];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Congratulations"
message:[NSString stringWithFormat:#"You tapped %i times in %i seconds!\n", tapAmount, originalCountdownTime]
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:#"Submit To High Score Leaderboard", #"View Leaderboard", nil];
alert.tag = 01;
[alert addSubview:username];
[alert show];
[alert release];
I think you need to add some new lines and a final space at the end of the message string.
[NSString stringWithFormat:#"You tapped %i times in %i seconds!\n\n\n ", tapAmount, originalCountdownTime]
Here is a UIAlertView replacement class that supports user-input, custom width, and more:
https://github.com/TomSwift/TSAlertView
i had the same issue , your code has the following condition
[alert addSubview:username];
[alert show];
add the UITextfield after the [alert show]; as
[NSString stringWithFormat:#"You tapped %i times in %i seconds!\n\n\n ", tapAmount, originalCountdownTime];
[alert show];
[alert addSubview:username];
Thats all.working fine.
You shouldn't use a UIAlertView in this manner. It was never intended for this type of user interaction and view customization:
From the iOS Human Interface Guidelines:
You can specify the text of the required title and optional message, the number of buttons, and the button contents in an alert. You can’t customize the width or the background appearance of the alert view itself, or the alignment of the text (it’s center-aligned).
Perhaps consider building a custom view instead?