简体   繁体   中英

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")

在此处输入图片说明

Reference

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM