Adding activityindicatorin alertVIew - iphone

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

Related

Uistepper in Uialertview

How can I show UIStepper in UIAlertView? Also suggest me any other alternative to show UIStepper in pop-up.
Try this.. Hope it will help you
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)];
UIAlertView *alert =[[UIAlertView alloc]init];// you can set your frame according to ypur requirment
[alert addSubview:stepper];
[alert show];
A better way of inserting views in UIAlertView would be to add them as a subview
Try the following
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:#"\n\n" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
UIStepper* stepper = [[UIStepper alloc] init];
stepper.frame = CGRectMake(12.0, 5.0, 100, 10);
[alert addSubview:stepper];
[alert show];

how to customize uialertview with textview?

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";

How to generate multi-line rather than single line with UIAlertView?

This is my code
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Added to Cart" message:#"Some items are added for time being!" delegate:self cancelButtonTitle:#"View Cart" otherButtonTitles:#"Continue \n Shopping", nil];
alert.tag = 20;
[alert show];
I get output like this:
I need like this:
I have manual solution for you. But I think its not a good solution:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Added to Cart" message:#"Some items are added for time being!" delegate:self cancelButtonTitle:#"View Cart" otherButtonTitles:#"", nil];
UILabel *buttonTitle = [[UILabel alloc] initWithFrame:CGRectMake(148, 102, 125, 40)];
buttonTitle.text = #"Continue Shopping";
buttonTitle.font = [UIFont boldSystemFontOfSize:15];
buttonTitle.textColor = [UIColor whiteColor];
buttonTitle.textAlignment = UITextAlignmentCenter;
buttonTitle.backgroundColor = [UIColor clearColor];
buttonTitle.numberOfLines = 2;
[alert addSubview:buttonTitle];
alert.tag = 20;
[buttonTitle release];
[alert show];
You can use it anyway....
UIAlertView doesn't support multi-line buttons. One option would be to just use "Continue" instead of "Continue Shopping" as the button title, otherwise you'd have to use a custom alert view component, e.g. CODialog (you might have to customize it a bit to allow multi-line buttons, but it should be easy).
I think you can try to set numbersOfLine property to label on button. But i don`t know will apple aprove that.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Added to Cart" message:#"Some items are added for time being!" delegate:self cancelButtonTitle:#"View Cart" otherButtonTitles:#"Continue \n Shopping", nil];
NSArray *subviewsArray = [alert subviews];
for (UIView *subview in subviewsArray) {
if ([subview isKindOfClass:[UIButton class]]) {
NSArray *btnSubviews = [subview subviews];
for (UIView *btnSubview in btnSubviews) {
if ([btnSubview isKindOfClass:[UILabel class]]) {
UILabel *title = (UILabel *)btnSubview;
title.numberOfLines = 2;
}
}
}
}
alert.tag = 20;
[alert show];
[alert release];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Added to Cart" message:#"Some items are added for time being!" delegate:self cancelButtonTitle:#"View Cart" otherButtonTitles:#"Continue \n Shopping", nil];
alert.tag = 20;
[[[alert buttons] objectAtIndex:1] setLineBreakMode:UILineBreakModeWordWrap];
[alert show];
This code does exactly what you need.
Note, however that
- [UIAlertView buttons] is undocumented
- [UIButton setLineBreakMode] is deprecated. You can however, replace it with
[button.titleLabel setLineBreakMode] which is essentially the same.

iphone 4 UIAlertView setAlertViewStyle unrecognized selector sent to instance

I used the below code to add textfield in UIAlertView. It works fine in Simulator(iOS SDK 5.0) but when i install in device(iOS 4.0.1) i get "Unrecognized selector sent to instance error"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter your name" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 9001;
[alert show];
[alert release];
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"My Test Alert" message:#"what do you want" delegate:nil cancelButtonTitle:#"tell me" otherButtonTitles:#"Cancel", nil];
[myAlert addTextFieldWithValue:#"nothing" label:#"say something"];
UITextField * aTextFld = [myAlert textFieldAtIndex: 0];
aTextFld.clearButtonMode = UITextFieldViewModeWhileEditing;
aTextFld.autocorrectionType = UITextAutocorrectionTypeNo;
[myAlert show];
[myAlert release];
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Hello!" message:#"Please enter your name:" delegate:self cancelButtonTitle:#"Continue" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
alertTextField.placeholder = #"Enter your name";
[alert show];
[alert release];
Include the library from here: http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
Try to use the below code:
AlertPrompt *prompt = [AlertPrompt alloc];
prompt.tag = 100;
prompt = [prompt initWithTitle:#"Enter a name" message:#" " delegate:self cancelButtonTitle:#"Cancel" okButtonTitle:#"Save"];
[prompt show];
[prompt release];

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];