Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emoji in iOS app Alerts and Notifications - Xcode/Swift

Tags:

ios

swift

emoji

I'm trying to add an emoji to an alert in Xcode but can't figure it out, any help is greatly appreciated! \xF0\x9F\x98\xB3

Code:

if ((self.liveStreamTitle.text?.characters.count) == 0)
        {

            let alertView = UIAlertController.init(title: "Forgot something?", message: "Video Title is empty EMOJIHERE", preferredStyle: UIAlertControllerStyle.Alert)
            alertView.addAction(UIAlertAction.init(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
            self.presentViewController(alertView, animated: true, completion: { 

            })

            return;

        }
like image 748
Yatko Avatar asked Jul 12 '16 23:07

Yatko


1 Answers

Actually you can just add them directly.

@IBAction func pressed(sender: AnyObject) {

let actionSheetController: UIAlertController = UIAlertController(title: "Are you sure?", message: "", preferredStyle: .Alert)
let cancelAction: UIAlertAction = UIAlertAction(title: "😡 NO", style: .Cancel) { action -> Void in
                //Do your task
}
actionSheetController.addAction(cancelAction)
let nextAction: UIAlertAction = UIAlertAction(title: "😍 YES", style: .Default) { action -> Void in
                //Do your task  
}
actionSheetController.addAction(nextAction)
self.presentViewController(actionSheetController, animated: true, completion: nil)

}

enter image description here

You can also do this using Unicode

let cancelAction: UIAlertAction = UIAlertAction(title: "\u{1F425}", style: .Cancel) { action -> Void in
let nextAction: UIAlertAction = UIAlertAction(title: "\u{1F426}", style: .Default) { action -> Void in

enter image description here

Or this using Unicode

let cancelAction: UIAlertAction = UIAlertAction(title: "\u{1F425} YES", style: .Cancel) { action -> Void in
let nextAction: UIAlertAction = UIAlertAction(title: "\u{1F426} NO", style: .Default) { action -> Void in

enter image description here

Emoji Unicode Chart

like image 83
Edison Avatar answered Sep 19 '22 15:09

Edison