4

I have an alert view in which i need to display a icon in between the texts of the alert view as like in the image below. This alert comes after uploading a video file to server in my app asynchronously. Any suggestions how to do it.

I am using Swift 2.2 xcode 7.3

enter image description here

Kautham Krishna
  • 967
  • 1
  • 14
  • 33

4 Answers4

2

If this image is an emoji or a unicode character you can add it directly in your text in a UIAlertViewController . Do NOT use UIAlertView since it has been deprecated.

However for better customizability I would recommend creating a custom view and adding it to your VC with a background overlay when it has to be shown

If you wish to create the custom alert, there are several open source examples here

Open source Custom Alerts

and If you would like to use a UIAlertController , this link has great examples

UIAlertController examples

halfer
  • 19,824
  • 17
  • 99
  • 186
Rajeev Bhatia
  • 2,974
  • 1
  • 21
  • 29
  • no this is not a unicode character. I have this image in my assets.Could you share a code snippet on how to show a `UIalertViewController` or `CustomView` to show like a alert when a background process is completed. – Kautham Krishna Jun 10 '16 at 06:32
  • Also for the background process, you should have some kind of completion closure that is called – Rajeev Bhatia Jun 10 '16 at 06:58
  • Yes in the completion closure i am showing this alert disregarding the Viewcontroller in which the user is currently viewing – Kautham Krishna Jun 10 '16 at 07:16
1

Why don't you create a custom View and use it as your alert ?

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let myAlert = storyboard.instantiateViewControllerWithIdentifier("alert")
myAlert.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
myAlert.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
self.presentViewController(myAlert, animated: true, completion: nil)

There you can do anything you like.

As far as emojis are related you can add them from :-

Xcode Edit ->  Emoji & Symbols

There are a lot of them to select from !!!

1

I solved it by creating a custom view controller where i placed a UIView at the centre with the dimensions similar to the alert box and set its constraints to centre horizontally, centre vertically , fixed width and fixed height. Inside i place a label with the text and the long space in between the place where the image has to be. then i place a image view with the image correctly in this gap. The view's corner radius is set to 13px and background color to match the alert box style.

Then as @Sushree's answer suggested, set the presentation style. But setting it programmatically didn't work for me. But setting it in the StoryBoard works for all IOS versions (8.0 to 9.3) as i checked.

Select UIViewController->Attributes inspector->Presentation->Over Current Context

I am using a UINavigationController as the RootViewController so i used the following code

if let wd = appDelegate.window {
                var vc = wd.rootViewController
                if(vc is UINavigationController){
                    vc = (vc as! UINavigationController).visibleViewController
                    vc!.presentViewController(PopupViewController, animated: false, completion: nil)
                }
            }

Reference answer

Community
  • 1
  • 1
Kautham Krishna
  • 967
  • 1
  • 14
  • 33
0

From this documentation of Apple, you could use unicode scalars which you would like to use.

Unicode Scalars

Behind the scenes, Swift’s native String type is built from Unicode scalar values. A Unicode scalar is a unique 21-bit number for a character or modifier, such as U+0061 for LATIN SMALL LETTER A ("a"), or U+1F425 for FRONT-FACING BABY CHICK ("").

Also, this answer can also be helpful.

Community
  • 1
  • 1
onkar
  • 4,427
  • 10
  • 52
  • 89