Yatko
Yatko

Reputation: 8805

Emoji in iOS app Alerts and Notifications - Xcode/Swift

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;

        }

Upvotes: 5

Views: 2771

Answers (1)

Edison
Edison

Reputation: 11987

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

Upvotes: 9

Related Questions