This is probably a ridiculously simple solution (I'm almost embarrassed to ask).
Corresponding piece of code from my view controller:
@IBOutlet weak var textLabel: NSTextField! @IBAction func getTimeButton(sender: AnyObject) { let currentDate = NSDate() let dateFormatter = NSDateFormatter() dateFormatter.timeStyle = .ShortStyle textLabel.stringValue = dateFormatter.stringFromDate(currentDate) }
Before pressing the button "Get time" the label "Press the button" will be centered:

After pressing the button, the label becomes left:

Label Attributes:

I set label restrictions, but the restrictions seem to get "reset" when a string value is given.
How to make the shortcut remain centered after setting the string value?
I also tried adding this to my controller, but to no avail:
let textAlignment = NSTextAlignment.CenterTextAlignment textLabel.alignment = textAlignment
source share