XYZ
XYZ

Reputation: 27397

Cocoa NSTextField text get cut off in view after changed to monospaced digital font

The text inside NSTextField gets cut off when I have the font changed to monospacedDigitSystemFont.

I have the following code in the viewDidLoad method. I do not understand why it has been cut off since sizeToFit has been called and the intrinsic size should be used.

The label at the bottom looks fine and it is using the default system font.

    labelTimeNow.sizeToFit()
    labelTimeNow.font = NSFont.monospacedDigitSystemFont(
        ofSize: labelTimeNow.font!.pointSize,
        weight: .medium
    )
    labelTimeNow.stringValue = DCClock.getCurrentTimeInFormat("HH:mm")

enter image description here

Reference

Upvotes: 1

Views: 246

Answers (1)

XYZ
XYZ

Reputation: 27397

Stupid me, I should call sizeToFit after changing the font spacing.

    labelTimeNow.font = NSFont.monospacedDigitSystemFont(
        ofSize: labelTimeNow.font!.pointSize,
        weight: .medium
    )
    labelTimeNow.stringValue = DCClock.getCurrentTimeInFormat("HH:mm")
    labelTimeNow.sizeToFit()

Upvotes: 1

Related Questions