Naveed
Naveed

Reputation: 3192

iOS alert banner/label?

I apologize if this question is very basic. I have been googling around but can't seem to find the api/reference for a drop down alert banner/label (I do not know the proper term for this), therefore I am posting here.

This: The label/banner which has "Please enter valid email address" in it.

enter image description here

So here a my questions:

Upvotes: 0

Views: 3288

Answers (3)

Shivam Bhalla
Shivam Bhalla

Reputation: 1909

For easier control over animating the alert, you can embed your custom view in a UIStackView and simply show/hide it in an animation block. That way will significantly reduce the amount of code needed to animate the visibility of the alert.

Upvotes: 0

lobianco
lobianco

Reputation: 6276

Check out my project - it might be just the thing you're looking for.

https://github.com/alobi/ALAlertBanner

Upvotes: 3

random
random

Reputation: 8608

Have a look here, I'm sure you will be able to find something to suite your needs.

The basic idea is that its simply a UIView that you animate down from the top of the screen (at the very basic). You can get a lot fancier by adding gradients, touch recognizers to dismiss it, etc. But pretty much to get the base line functionality you would just do something like this:

//Create a view to hold the label and add images or whatever, place it off screen at -100
UIView *alertview = [[UIView alloc] initWithFrame:CGRectMake(0, -100, CGRectGetWidth(self.view.bounds), 100)];

//Create a label to display the message and add it to the alertView
UILabel *theMessage = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(alertview.bounds), CGRectGetHeight(alertview.bounds))];
theMessage.text = @"I'm an alert";
[alertview addSubview:theMessage];

//Add the alertView to your view
[self.view addSubview:alertview];

//Create the ending frame or where you want it to end up on screen, in this case 0 y origin
CGRect newFrm = alertview.frame;
newFrm.origin.y = 0;

//Animate it in
[UIView animateWithDuration:2.0f animations:^{
    alertview.frame = newFrm;
}];

Upvotes: 4

Related Questions