how to customize uialertview with textview? - iphone

here my problem is how to decrement the size uilaertview?
thanks
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
alert.title = #"Terms of Service";
alert.message = #"\n\n\n\n\n\n\n\n\n";
alert.delegate = self;
[alert addButtonWithTitle:#"Cancel"];
[alert addButtonWithTitle:#"Review"];
[alert addSubview:textView];
[alert show];

set your alert.frame = CGRectMake(0, 20, 50, 50); and use a simple message instead of using alert.message = #"\n\n\n\n\n\n\n\n\n";
Eg:
alert.message = #"my message";
or use the below UIAlertView delegate to set the frame
- (void)willPresentAlertView:(UIAlertView *)alertView{
alertView.center = your own CGPoint;
}

Remove
alert.message = #"\n\n\n\n\n\n\n\n\n";

Related

Changing width and height of Alert Message i-Phone

Was wondering what the correct way would be to initialise my alert popup with a smaller window
-(void)alertMessage1:(NSString*) title:(NSString*) message1 {
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:#"Successfully uploaded!" message:message1 delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
}
You can create a UIAlertview as you suggested like this
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Title Here" message:#"Message here" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];
[alert release];
and if you want to adjust the frame them use
- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.f);
NSArray *subViewArray = alertView.subviews;
for(int x=0;x<[subViewArray count];x++){
if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
{
UILabel *label = [subViewArray objectAtIndex:x];
label.textAlignment = UITextAlignmentLeft;
}
}
}
In this alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.f); the CGRectMake(X-position, Y-Position, width, Height). Change it and your work will be done.
You should create custom AlertView or use one of these :
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=alertview
For the question you raised in comment changing the background color of UIAlertview you can add the background image like this directly. I am not sure if you can add the color or not.
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:#"Atention" message: #"YOUR MESSAGE HERE", nil) delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[theAlert show];
UILabel *theTitle = [theAlert valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
UIImage *theImage = [UIImage imageNamed:#"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[theAlert layer] setContents:[theImage CGImage]];

UitextFields in UIAlertView selecting iOS

I have three UITextfields in UIAlertView, while tap on one UITextfield and try to tap on other its not selecting and creating a problem, also problem of resigning first responder, is it not good choice of using UITextfield in UIAlertView
- (IBAction)heightMethod:(id)sender
{
self.centimeterTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
centimeterTextField.placeholder = #" Centimeters";
self.centimeterTextField.delegate=self;
self.centimeterTextField.tag=3;
[ self.centimeterTextField setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview: self.centimeterTextField];
self.ptextfield = [[UITextField alloc] initWithFrame:CGRectMake(40, 80.0, 80, 25.0)]; ptextfield.placeholder = #" Feet";
self.ptextfield.delegate=self;
self.ptextfield.tag=4;
[self.ptextfield setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview:self.ptextfield];
self.ptextfieldInches = [[UITextField alloc] initWithFrame:CGRectMake(140, 80.0, 80, 25.0)]; ptextfieldInches.placeholder = #" Inches";
self.ptextfieldInches.delegate=self;
self.ptextfieldInches.tag=5;
[ptextfieldInches setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview:ptextfieldInches];
[self.centimeterTextField setKeyboardType:UIKeyboardTypeDecimalPad];
[self.ptextfieldInches setKeyboardType:UIKeyboardTypeDecimalPad];
[self.ptextfield setKeyboardType:UIKeyboardTypeDecimalPad];
self.alertHeight.tag=1;
[self.alertHeight show];
}
- (void) presentSheet {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Enter Information"
message:#"Specify the Name and URL" delegate:self cancelButtonTitle:#"Cancel"otherButtonTitles:#"OK", nil];
[alert addTextFieldWithValue:#"" label:#"Enter Name"];
[alert addTextFieldWithValue:#"http://" label:#"Enter URL"];
UITextField *tf = [alert textFieldAtIndex:0];
tf.clearButtonMode = UITextFieldViewModeWhileEditing;
tf.keyboardType = UIKeyboardTypeAlphabet;
tf.keyboardAppearance = UIKeyboardAppearanceAlert;
tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
tf.autocorrectionType = UITextAutocorrectionTypeNo;
// URL field
tf = [alert textFieldAtIndex:1];
tf.clearButtonMode = UITextFieldViewModeWhileEditing; tf.keyboardType = UIKeyboardTypeURL;
tf.keyboardAppearance = UIKeyboardAppearanceAlert; tf.autocapitalizationType = UITextAutocapitalizationTypeNone; tf.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show];
}
You can now create a UIAlertView with a style.
UIAlertView now has a property - alertViewStyle that you can set to one of the enum values
1. UIAlertViewStyleDefault
2. UIAlertViewStyleSecureTextInput
3. UIAlertViewStylePlainTextInput
4. UIAlertViewStyleLoginAndPasswordInput
Once you've created the alert view, you set it style and display it. After dismissing the alert, you can access the contents of the fields using the textFieldAtIndex property of the alert view.
or else you can use this one also.,
IAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:#"Enter Name"];
[dialog setMessage:#" "];
[dialog addButtonWithTitle:#"Cancel"];
[dialog addButtonWithTitle:#"OK"];
UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 70.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];
Hope this information helps. Thank you.

How to prompt user for text input in Alert view

I am writing a section of code where it would be best if I could use a pop up box something like UIAlertView and prompt the user to enter text like a password.
Any pointers on an elegant way of doing this?
Things are much simpler in iOS 5, just set the alertViewStyle property to the appropriate style (UIAlertViewStyleSecureTextInput, UIAlertViewStylePlainTextInput, or UIAlertViewStyleLoginAndPasswordInput). Example:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Password" message:#"Enter your password:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show];
> Simple You can apply like this
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Filename" message:#"Enter the file name:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show]
The best way that I've found to do this is to follow this tutorial: http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html
The code used to achieve this is (taken directly from that great tutorial):
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:#"Server Password" message:#"\n\n\n"
delegate:self cancelButtonTitle:NSLocalizedString(#"Cancel",nil) otherButtonTitles:NSLocalizedString(#"OK",nil), nil];
UILabel *passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(12,40,260,25)];
passwordLabel.font = [UIFont systemFontOfSize:16];
passwordLabel.textColor = [UIColor whiteColor];
passwordLabel.backgroundColor = [UIColor clearColor];
passwordLabel.shadowColor = [UIColor blackColor];
passwordLabel.shadowOffset = CGSizeMake(0,-1);
passwordLabel.textAlignment = UITextAlignmentCenter;
passwordLabel.text = #"Account Name";
[passwordAlert addSubview:passwordLabel];
UIImageView *passwordImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"passwordfield" ofType:#"png"]]];
passwordImage.frame = CGRectMake(11,79,262,31);
[passwordAlert addSubview:passwordImage];
UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(16,83,252,25)];
passwordField.font = [UIFont systemFontOfSize:18];
passwordField.backgroundColor = [UIColor whiteColor];
passwordField.secureTextEntry = YES;
passwordField.keyboardAppearance = UIKeyboardAppearanceAlert;
passwordField.delegate = self;
[passwordField becomeFirstResponder];
[passwordAlert addSubview:passwordField];
[passwordAlert setTransform:CGAffineTransformMakeTranslation(0,109)];
[passwordAlert show];
[passwordAlert release];
[passwordField release];
[passwordImage release];
[passwordLabel release];
If my app was not to be released for yet a months or two, then I would login to http://developer.apple.com, look at the iOS 5 beta area, and see if UIAlertView might have something in store for us.
I think it would be helpful to know that UIAlertView is not modal so the alert will not block.
I ran into this problem where I wanted to prompt the user for input then continue and then use that input in the code after. But instead the code after the [alert show] would run first until you reached the end of the run loop then the alert would display.
Optimized code:
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:#"Password"
message:#"Please enter the password:\n\n\n"
delegate:self
cancelButtonTitle:NSLocalizedString(#"Cancel",nil)
otherButtonTitles:NSLocalizedString(#"OK",nil), nil];
UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(16,83,252,25)];
passwordField.borderStyle = UITextBorderStyleRoundedRect;
passwordField.secureTextEntry = YES;
passwordField.keyboardAppearance = UIKeyboardAppearanceAlert;
passwordField.delegate = self;
[passwordField becomeFirstResponder];
[passwordAlert addSubview:passwordField];
[passwordAlert show];
[passwordAlert release];
[passwordField release];

Adding activityindicatorin alertVIew

I want to add a activity indicator in alertView.
How to do this?
I think you can do by this -
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"title" message:#"\n\n" delegate:nil cancelButtonTitle:#"cancel" otherButtonTitles:nil];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0f, 50.0f, 20.0f, 20.0f)];
[activityIndicator startAnimating];
[alertview addSubview:activityIndicator];
[alertview show];
[alertview release];
[activityIndicator release];
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:#"Configuring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
Check the tutorial here

How to change the frame of AlertView in iPhone App...?

I want to Add TextBox on AlertView. But When i'm adding, it overlaps little with buttons on it...So i want to increase the height and width of alertview...Could Anybody tell any idea??
Try the following code:
UIAlertView alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Title", nil)
message:NSLocalizedString(#"Message\n\n\n", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(#"Cancel", nil)
otherButtonTitles:NSLocalizedString(#"OK", nil), nil];
UITextField textField = [[UITextField alloc] initWithFrame:CGRectMake(16.0, 100.0, 250.0, 25.0)];
textField.borderStyle = UITextBorderStyleRoundedRect;
[alertView addSubview:textField];
[textField release];
[alertView show];
[alertView release];
try this
UITextField *TextField = [[UITextField alloc] initWithFrame:CGRectMake(22.0, 50.0, 240.0, 30.0)];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Enter\n\n" message:#"" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView addSubview:TextField];
[alertView show];