开发者

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:

开发者_如何学JAVA

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:

NSAttributedString / NSTextTab Alignment Issue

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.

NSAttributedString / NSTextTab Alignment Issue

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.

NSAttributedString / NSTextTab Alignment Issue

Apparently, the layout needs to be "Scrolls" (was "Truncates") in order to produce the desired effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜