Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make message of UIAlertController copyable in swift2, iOS9?

I've a simple question: How can I make the message of an UIAlertController be selectable and copyable by the user?

The controller is initiated like so:

let alertController = UIAlertController(title: "Hello World", message: "Copy Me!", preferredStyle: .Alert)

and displayed like so:

presentViewController(alertController, animated: true, completion: nil)
like image 400
Quantaliinuxite Avatar asked Dec 19 '22 23:12

Quantaliinuxite


2 Answers

Adam's correct that UIAlertController doesn't provide text selection functionality, so a traditional copy/paste solution isn't going to work. You could alternatively provide a button on your UIAlertController that copies a string to the pasteboard.

UIPasteboard.general.string = "Copy Me!"
like image 141
Chris Droukas Avatar answered Jan 17 '23 15:01

Chris Droukas


It is not possible. UIAlertController has no such functionality. It was implemented with UILabel components, which don't support copying text. You are not allowed to subclass UIAlertController either. The only option is to implement your own controller instead.

like image 39
Adam Avatar answered Jan 17 '23 14:01

Adam