Setting usesSingleLineMode to true for a non-system font causes the top of the text to be clipped.
I've created 3 very simple test cases that illustrate this:
- good : non-system font, with usesSingleLineMode = false. Works fine.
- bad : non-system font with usesSingleLineMode = true. Does not work.
- system : system font with usesSingleLineMode = true. Works fine.
Add the following to the viewDidLoad() method of a new Cocoa OSX application:
// 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 a storyboard, set the font in IB and check Uses Single Line Mode in IB it works fine! But, it would be impractical to build the overall view in IB, thus I want to programmatically create it.
Why is this happening? Have I missed some important setting (I've tried adjusting many NSTextField and NSTextFieldCell parameters to no avail? Is there a workaround?