Reputation: 22633
I'm attempting to use NSAttributedStrings (in conjunction with NSTextTabs) to create the following layout:
[ Title # ] <-- Useable in NSTableViews, NSMenuItems, etc.
[ Another Title # ]
[ T3 # ]
The code I'm attempting is:
NSMutableParagraphStyle *tabStyle = [[NSMutableParagraphStyle alloc] init];
[tabStyle setTabStops: [NSArray array]];
[tabStyle addTabStop: [[NSTextTab alloc] initWithType: NSRightTabStopType location: 200.0]];
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"\t"]];
[attrString addAttribute: NSParagraphStyleAttributeName value: tabStyle range: NSMakeRange(0, [attrString length])];
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"1"]];
Where attrString
is an NSMutableAttributeString, currently set to the "Title".
However, using this code (which I would assume would produce the desired output), produces the following:
When I remove the references to NSTextTabs, like so:
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"\t"]];
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"1"]];
I get the expected output of uneven tabbing.
Why is the NSAttributedString seemingly ignoring the NSParagraphStyle/NSTextTabs?
What can I do to fix this?
Upvotes: 2
Views: 1210
Reputation: 22633
Found the issue, by making an NSTextView in IB and placing the AttributedString into it.
Apparently, the layout needs to be "Scrolls" (was "Truncates") in order to produce the desired effect.
Upvotes: 2