Jakob Jakob - 18 days ago 5
Swift Question

Use NSTextField as replacement for NSLabel

As AppKit doesn't provide an NSLabel, we need to find something similar. NSTextField might be the thing I need?

How to do this in Swift?

[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];


Thanks for your help!

Answer

Yes, NSTextField is the right one.

It's what Xcode suggests when you ask for a label:

enter image description here

You can create the label from Interface Builder, or from code:

enter image description here

And set your values like this, for example:

let tf = NSTextField()
tf.isBezeled = false
tf.drawsBackground = false
tf.isEditable = false
tf.isSelectable = false
Comments