Setting usesSingleLineMode to true for a non-system font causes the top of the text to be trimmed.
I created 3 very simple test cases that illustrate this:
- good: non-system font using SingleLineMode = false. It works great.
- bad: non-system font with usesSingleLineMode = true. Does not work.
- system: system font with usesSingleLineMode = true. It works great.
Add a new Cocoa OSX application to the viewDidLoad () method:
// Do any additional setup after loading the view. let good = NSTextField(frame: NSRect(x: 0, y: 0, width: 800, height: 55)) good.usesSingleLineMode = false good.font = NSFont(name: "HelveticaNeue-UltraLight", size: 24) good.stringValue = "Good usesSingleLineMode false " self.view.addSubview(good) let bad = NSTextField(frame: NSRect(x: 0, y: 100, width: 800, height: 55)) bad.usesSingleLineMode = true bad.font = NSFont(name: "HelveticaNeue-UltraLight", size: 24) bad.stringValue = "Bad usesSingleLineMode true" self.view.addSubview(bad) let system = NSTextField(frame: NSRect(x: 0, y: 200, width: 800, height: 55)) system.usesSingleLineMode = true system.font = NSFont.systemFontOfSize(24) system.stringValue = "Good usesSingleLineMode true, System Font" self.view.addSubview(system)

If I create the same bad
NSTextField using Interface Builder in the storyboard, set the font in IB and check the Single Line Mode in IB, it works great! But it would be impractical to build a general view in IB, so I want to programmatically create it.
Why is this happening? I missed some important parameter (I tried setting many of the NSTextField and NSTextFieldCell parameters to no avail? Is there a workaround?
source share