Swift 4: Copy a UILabel in iOS

By default a UILabel doesn’t get any copy & paste commands in iOS. After all, it’s a label, why would you want to copy a label? It turns out, you might want to do that, if you are “abusing” a label to show something useful and in that case you probably want the entire label to be copied in one go, no “select”, just a simple copy.

This problem was beautifully solved on stackoverflow and you can see the solution here. For anyone else, the class is below.

In the end you implement this class:

…then you go do the identity inspector of your Label and select the Class as a Custom Class for the UILabel

and then in your app, as you touch and hold on your Label, you’ll get a simple copy command:

And now you also know a dirty little secret of one of my Apps, the article title is a UILabel – I feel appropriately ashamed…

You Might Also Like