NSAttributedString / NSTextTab Alignment Issue
GOAL:
I'm attempting to use NSAttributedStrings (in conjunction with NSTextTabs) to create the following layout:
[ Title # ] <-- Useable in NSTableViews, NSMenuItems, etc.
[ Another Title # ]
[ T3 # ]
ATTEMPTED SOLUTION:
开发者_如何学JAVAThe 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:
FURTHER INFORMATION:
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.
BOTTOM LINE:
Why is the NSAttributedString seemingly ignoring the NSParagraphStyle/NSTextTabs?
What can I do to fix this?
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.
精彩评论