line spacing in Cocoa Label controls

Now that I’ve started using Xojo more persistently numerous issues are coming to the surface compared to RB. It seems the line spacing in Cocoa labels is surprisingly larger than under RB/Carbon. So many of my info boxes have their text cut off at the bottom. Is there a way to condense the line spacing in Cocoa label controls so it matches what we had in RB/Carbon? The space is wasteful on a busy window. Reducing the text size of course reduces the spacing but then the characters are too small.
P.

With MBS Plugin:

[code] dim n as NSTextFieldMBS = me.NSTextFieldMBS

dim a as NSAttributedStringMBS = n.attributedStringValue

dim p as NSParagraphStyleMBS = a.attributeAtIndex(a.NSParagraphStyleAttributeName, 0)
dim m as NSMutableParagraphStyleMBS = p.mutableCopy
m.setLineSpacing 5

dim s as NSMutableAttributedStringMBS = a.mutableCopy
s.addAttribute(a.NSParagraphStyleAttributeName, m, new NSRangeMBS(0, s.length))

n.attributedStringValue = s[/code]

As you see we set the line spacing and put back the new paragraph style with the attributed string.

perfect, thx Christian.
p.

See feedback://showreport?report_id=30154

yes related. What we need is a myLabel.LineSpacing property, or have labels spaced the same in Carbon and Cocoa.

Yosmite and NSTextField has some strange behaviour regarding linespaces. Running with Yosmite the text is stretched a lot compared running OSX10.9 or lower.

Well, when using NSTextFieldMBS anyway.
Not sure if it is a MBS or Yosmite bug.

[quote=120374:@Christian Schmitz] dim n as NSTextFieldMBS = me.NSTextFieldMBS

dim a as NSAttributedStringMBS = n.attributedStringValue

dim p as NSParagraphStyleMBS = a.attributeAtIndex(a.NSParagraphStyleAttributeName, 0)
dim m as NSMutableParagraphStyleMBS = p.mutableCopy
m.setLineSpacing 5

dim s as NSMutableAttributedStringMBS = a.mutableCopy
s.addAttribute(a.NSParagraphStyleAttributeName, m, new NSRangeMBS(0, s.length))

n.attributedStringValue = s[/quote]

where to use the code above??

in the open event of a subclassed TextEdit?

let me try…

I just had it in the open event of the control.

i try to on the open event of my subclassed Label. it work first time when i set the “m.setLineSpacing 10” but it revert back to the standard line spacing for some reason.

i have 1 tabpanel with 2 tabs which have a combobox for my list of reports for client and another stock. the code above work when i select one of the report from the client combo and show description of that report. when i change the tab to the stock reports and select a stock report, the line spacing change back to original.

Try GotFocus.

ok… will try that and see what happen

just realise there is NO GotFocus for label controls

[quote=120374:@Christian Schmitz]dim n as NSTextFieldMBS = me.NSTextFieldMBS

dim a as NSAttributedStringMBS = n.attributedStringValue

dim p as NSParagraphStyleMBS = a.attributeAtIndex(a.NSParagraphStyleAttributeName, 0)
dim m as NSMutableParagraphStyleMBS = p.mutableCopy
m.setLineSpacing 5

dim s as NSMutableAttributedStringMBS = a.mutableCopy
s.addAttribute(a.NSParagraphStyleAttributeName, m, new NSRangeMBS(0, s.length))

n.attributedStringValue = s[/quote]

I get a nil exception on m at line :

dim m as NSMutableParagraphStyleMBS = p.mutableCopy

Right. Sorry. Depends when line spacing reverts, but you should be able to determine when it does, then place the call in the appropriate event. Maybe the window Paint event ?

I wanted to experiment, but I get this pesky nil exception on Christian code and will not be able to help until it works.

don’t use it on the text area micheal, u will get an nil exception error in this line

“dim a as NSAttributedStringMBS = n.attributedStringValue”

[quote=122066:@Richard Duke]don’t use it on the text area micheal, u will get an nil exception error in this line

“dim a as NSAttributedStringMBS = n.attributedStringValue”[/quote]

I use it on a label …

it work on the label… but not all the times… i am going to do a bit more research.

well, it will not work in Carbon as it requires Cocoa project.