-1

I am making an app and want to create a custom alert. I have found the following way to do it:

  1. Create a view controller in story board and set its identifier.
  2. Set its background to clear.
  3. Create a view in it and set all the buttons and labels.
  4. Call it from the other controller like this:

    let alertViewController = self.storyboard.instantiateViewControllerWithIdentifier("alertViewController") as! AlertViewController
    
    self.presentViewController(alertViewController, animated: true, completion: nil)
    

But what I want to do is, presenting multiple alerts simultaneously like this:

enter image description here

I searched for this but only found ways in which second alert will be displayed when first alert is responded, but not at the same time. How can I achieve what is shown in the attached image?

James Z
  • 12,209
  • 10
  • 24
  • 44
kinza
  • 535
  • 11
  • 31

2 Answers2

1

It looks like this is a modal ViewController with a UIVisualEffectView for its background so its blurring the background. You need to create an array of alert messages then, for each message you add one alert view with that message to the view controller. Each message view should have constraints width constant, height constant, centerX to superview and centerY to superview. You can then set the transform of each view to scale it down and move it up based on its index in the message array. Something like yOffset = (messages.count - index) * spacing and scale = exp(0.95, (messages.count - index)). The message in front has the indentity matrix for its transform. As you dismiss the messages animate the transform change so they all scale up and slide down.

Josh Homann
  • 15,933
  • 3
  • 30
  • 33
0

Is there a max number of the number of alerts shown at the same time? If yes, how many is it?

I would suggest making it not using UIViewController but easier: using UIView. And you may show them all on your current ViewController.

How to create a custom UIView: link.

Hope it helps.

Tung Fam
  • 7,899
  • 4
  • 56
  • 63
  • Alright. If I follow the above tutorial then how can i display multiple alert views at a time as shown in the attached image above? – kinza Nov 26 '17 at 15:35
  • I think you can figure it out. There will never be the same solution for your custom UI. I also can't answer without more context. I also asked you a question but you decided not to answer (which is not polite and not stackoverflow style at all). But shortly: you can create 2 types of alerts of 2 sizes: 1 small 1 big. Show the small and then show the big one which will be added on top and hide the small one behind. But I'm sure my answer can't be correct with a limited context. Sorry. – Tung Fam Nov 26 '17 at 15:46