Unable to add UITextField to UIAlertView on iOS7…works in iOS 6

You can’t easily alter the view hierarchy of a UIAlertView in iOS 7. (Nor should you; the documentation specifically tells you not to.) Head over to the developer forums to see a long discussion about it. One alternative in your case is to set alert.alertViewStyle = UIAlertViewStylePlainTextInput; This will add a text field for you. … Read more

Is it possible to NOT dismiss a UIAlertView

Yes. Subclass UIAlertView and then overload -dismissWithClickedButtonIndex:animated:, e.g. @implementation MyAlertView -(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { if (buttonIndex should not dismiss the alert) return; [super dismissWithClickedButtonIndex:buttonIndex animated:animated]; } @end Unofficially you can define a -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button; method to the delegate which will make it bypass -dismissWithClickedButtonIndex:animated:, but it’s undocumented, so I don’t know whether it’s suitable for you.

Is it possible to show an Image in UIAlertView?

You can do it like: UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@”OK” otherButtonTitles:nil]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)]; NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@”smile.png”]]; UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path]; [imageView setImage:bkgImg]; [successAlert addSubview:imageView]; [successAlert show]; This will add a image in the right corner of … Read more

UIAlertView/UIAlertController iOS 7 and iOS 8 compatibility

The detection pattern is identical to the Objective-C style. You need to detect whether the current active runtime has the ability to instantiate this class if objc_getClass(“UIAlertController”) != nil { println(“UIAlertController can be instantiated”) //make and use a UIAlertController } else { println(“UIAlertController can NOT be instantiated”) //make and use a UIAlertView } Don’t try … Read more

Changing the background color of a UIAlertView?

Background of AlertView is an image And you can change this image 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]; … Read more

Check if a UIAlertView is showing

Why not just check the visible property, maintained by the UIAlertView class? if (_alert) //alert is a retained property { self.alert = [[[UIAlertView alloc] initWithTitle:@”Your Title” message:@”Your message” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”OK”] autorelease]; } if (!_alert.visible) { [_alert show]; }

Custom Alert (UIAlertView) with swift

Code tested in Swift 5 and Xcode 10 How to make your own custom Alert I was wanting to do something similar. First of all, UIAlertView is deprecated in favor of UIAlertController. See this answer for the standard way to display an alert: How would I create a UIAlertView in Swift? And both UIAlertView and … Read more

Writing handler for UIAlertAction

Instead of self in your handler, put (alert: UIAlertAction!). This should make your code look like this alert.addAction(UIAlertAction(title: “Okay”, style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in println(“Foo”)})) this is the proper way to define handlers in Swift. As Brian pointed out below, there are also easier ways to define these handlers. Using his methods is discussed … Read more

UIAlertView first deprecated IOS 9

From iOS8 Apple provide new UIAlertController class which you can use instead of UIAlertView which is now deprecated, it is also stated in deprecation message: UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead So you should use something like this UIAlertController * alert = [UIAlertController alertControllerWithTitle:@”Title” message:@”Message” preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* yesButton = [UIAlertAction … Read more