Help with NSAttributedString

I want to change the font size (system font) of a NSAttributedString. How do I do that with MacOSLib?

What have you tried that hasn’t worked?

Not sure how XOJO handles it… but if it helps here is some SWIFT code that does it

  sa.addAttribute(NSFontAttributeName , value: UIFont(name: "Courier-Bold", size: 17)!, range: NSMakeRange(2,8))

I tried:

Dim AttributedTitle As New NSMutableAttributedString("Test")
Call AttributedTitle.AddAttribute("NSFontAttributeName", NSFont.SystemFontOfSize(9))

But that gives an Exception Message: -[NSConcreteAttributedString addAttribute:value:range:]: unrecognized selector sent to instance 0xa017bd0

This looks as if instead of a mutableAttributedString an unmutable type is instantiated. Have you checked the constructur if it returns the mutableAttributedString class ptr?

I’m really shooting in the dark here, trying to figure this stuff out. I came up with this and it seems to work now.

Dim AttributedTitle As NSAttributedString
AttributedTitle = New NSAttributedString("Test")
Dim MutableAttributedTitle As NSMutableAttributedString
MutableAttributedTitle = New NSMutableAttributedString(AttributedTitle.MutableCopy)
Call MutableAttributedTitle.AddAttribute("NSFontAttributeName", NSFont.SystemFontOfSize(11))