Animate Images in UIAlertView - ios

I am trying to play an animation of images in a UIAlertView.
Here is my code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIImageView *animation = nil;
animation.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"Comment-Edit-48.png"],[UIImage imageNamed:#"Share-48.png"],[UIImage imageNamed:#"Comment-Edit-48.png"],[UIImage imageNamed:#"Play-48.png"], nil];
[animation setAnimationRepeatCount:10];
animation.animationDuration = 1.5;
[animation startAnimating];
[alert addSubview:animation];
[alert show];
[alert release];
Can anyone please tell me what I did wrong here ?

This is due to your animation imageView frame size. You need to alloc it with certain frame size of your animation imageView. If you don't do that then it will not occupy any memory space. A nil object would have been add inside UIAlertView. Try this below given code
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIImageView *animation =[[UIImageView alloc] initWithFrame:CGRectMake(120, 50, 50, 45)];
animation.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"Comment-Edit-48.png"],[UIImage imageNamed:#"Share-48.png"],[UIImage imageNamed:#"Comment-Edit-48.png"],[UIImage imageNamed:#"Play-48.png"], nil];
[animation setAnimationRepeatCount:10];
animation.animationDuration = 1.5;
[animation startAnimating];
[alert addSubview:animation];
[alert show];
[alert release];
Set this frame size and it works fine. I hope it will help you. Thanks

Related

Adding UIImage to UIAlertView is not working as expected

I am working on an app. I tried to add an UIIMage to UIAlertView using below code,
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Instruction"
message:#"Please TAP on Screen to Continue."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 50, 32, 32)];
UIImage *img = [UIImage imageNamed:#"pendingImg.png"];
[imageView setImage:img];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alert setValue:imageView forKey:#"accessoryView"];
}else{
[alert addSubview:imageView];
}
[alert show];
My image is of dimension 32 × 32 pixels. I am getting the alert as shown,
Should I add constraints to this image? or anything else to be made?
You can set imageView contentMode to UIViewContentModeScaleAspectFit,
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Instruction"
message:#"Please TAP on Screen to Continue."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 50, 32, 32)];
UIImage *img = [UIImage imageNamed:#"pendingImg.png"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[imageView setImage:img];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alert setValue:imageView forKey:#"accessoryView"];
}else{
[alert addSubview:imageView];
}
[alert show];
Might be Anbu.Karthik suggested link comment also helpful for you.
try this
UIAlertView* alert = [UIAlertView alloc] initWithTitle: #"Instruction" message: #"Please TAP on Screen to Continue." delegate:nil cancelButtonTitle:#"no" otherButtonTitles:#"yes", nil];
UIImage* img = [UIImage imageNamed:#"pendingImg.png"];
UIImageView* imgview = [UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
[img setImage:imgMyImage];
[alert setValue: imgview forKey:#"accessoryView"];
[alert show];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle: #"Instruction" message: #"Please TAP on Screen to Continue." delegate:nil cancelButtonTitle:#"no" otherButtonTitles:#"yes", nil];
UIImage* img = [UIImage imageNamed:#"add.png"];
UIImageView* imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
[imgview setImage:img];
[alert setValue: imgview forKey:#"accessoryView"];
[alert show];
}

Why is this UIAlertView's Position not changing?

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Blah"
message:nil
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Enter", nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[alert textFieldAtIndex:0].delegate = self;
alert.delegate = self;
[alert show];
alert.frame = CGRectMake(0,0,200,100);
I've tried adding an AffineTransform as well. But it just doesn't change. Can someone help me out here?
Turns out this is just Apple trying to get everyone to move to UIAlertControllers. UIAlertController moves automatically. So that would be my suggestion to anyone here.

UIAlertViewStyleLoginAndPasswordInput placeholder text won't set

I have an app that uses a UIAlertViewStyleLoginAndPasswordInput alert view. Everything works fine with the exception that the password field's placeholder text has some strange behavior. On my sim it refuses to change from 'Password' regardless of what I set it as. And Ive been having reports that it flip flops between 'Password" and the value I wish to set it at. This seems to be all iOS7 related.
I am attempting to set these values in the 'willPresentAlertView' delegate.
- (void)willPresentAlertView:(UIAlertView *)alertView
{
...
else if (alertView.tag == UIAlertViewTagInactivityTimeOut)
{
badgeNumberTextField = [alertView textFieldAtIndex:0];
verifyBadgeNumberTextField = [alertView textFieldAtIndex:1];
[badgeNumberTextField setPlaceholder:#"Badge Number"];
[verifyBadgeNumberTextField setPlaceholder:#"Verify Badge Number"];
[verifyBadgeNumberTextField setSecureTextEntry:NO];
[badgeNumberTextField setFont:[UIFont systemFontOfSize:ALERT_VIEW_TEXTFIELD_TEXT_FONT]];
[verifyBadgeNumberTextField setFont:[UIFont systemFontOfSize:ALERT_VIEW_TEXTFIELD_TEXT_FONT]];
[badgeNumberTextField setKeyboardType:UIKeyboardTypeNamePhonePad];
[verifyBadgeNumberTextField setKeyboardType:UIKeyboardTypeNamePhonePad];
[badgeNumberTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
[verifyBadgeNumberTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
[badgeNumberTextField setDelegate:self];
[verifyBadgeNumberTextField setDelegate:self];
...
//other code
}
}
Have you tried set the placeholder where you create the UIAlertView?
Try this:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Login", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert textFieldAtIndex:0].placeholder = #"Username placeholder";
[alert textFieldAtIndex:1].placeholder = #"Password placeholder";
[alert show];

Can we programmatically insert text in UIAlertView's textfield, iOS7

Can we programmatically insert text in UIAlertView's textfield, iOS7
Created UIAlertView with textinput in IOS7.
Can anyone help me with "inserting text programatically in textfield"?
Hopefully this will give answer for your question.
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title = #"Enter Info";
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView addButtonWithTitle:#"Cancel"];
[alertView addButtonWithTitle:#"OK"];
[alertView textFieldAtIndex:0].text = #"My Text";
[alertView show];
You can achieve this by using this code
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"" message:#"whatever you like" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:#"Cancel", nil];
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
[alert textFieldAtIndex:0].text=#"Hello";
[alert show];
and result will be like this:
Please try to use like this..
UIAlertView* av = [[UIAlertView alloc] init];
[av setDelegate:self];
[av setTitle:#"Hi"];
[av setMessage:nil];
[av addButtonWithTitle:#"Cancel"];
[av addButtonWithTitle:#"OK"];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
[av textFieldAtIndex:0].text = #"Text";
You can use text property to set text inside textfield.
textFiled.text = #"YOUR TEXT";

UITextField in input dialog not showing up

I am implementing a simple dialog which asks for a name. This is my code:
UIAlertView* 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, 20.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];
It used to work fine but in iOS 7 the textfield doesn't show up. Can anyone help?
this will not work anymore in iOS7
try this instead
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(#"Enter a phone number",nil) delegate:self cancelButtonTitle:NSLocalizedString(#"Cancel",nil) otherButtonTitles:NSLocalizedString(#"OK",nil), nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert setTag:1];
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] resignFirstResponder];
[[alert textFieldAtIndex:0] setPlaceholder:NSLocalizedString(#"Enter Number here", nil)];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
[alert show];
[alert release];
You can change your keyboard type for your requirement.
Good luck:)
Try to use like this...And there is no need to add text field as subview.
UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:#"Enter Name"];
[dialog setMessage:#" "];
[dialog addButtonWithTitle:#"Cancel"];
[dialog addButtonWithTitle:#"OK"];
dialog.alertViewStyle = UIAlertViewStylePlainTextInput;
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 20.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];

Resources