使用NSCell在NSTable中右对齐文本

问题描述 投票:0回答:1

我有一个NSTableView,基于单元格,具有几列,并已在IB和所有作品中为文本设置了正确的对齐方式。在扩展方面,因此决定使用NSCell在表列中自定义打印。我可以毫无问题地更改字体颜色和字体大小,但是我无法通过接缝使文本在单元格中正确对齐。我尝试了许多不同的方法,没有任何缝隙可以工作。希望有人有一个可行的想法。

尝试以下内容:

NSMutableParagraphStyle *paraStyle [[NSMutableParagraphStyle alloc] init];
[paraStyle setAlignment: NSRightTextAlign];
SDictionary *textAttributes = @{NSParagraphStyleAttributedName: paraStyle, NSFontAttributedName: [NSFont systemFontOfSize: 13]};
myPoint.x = cellFrame.origin.x;
myPoint.y = cellFrame.origin.y;
[myString drawAtPoint: thePoint withAttributes: textAttributes];

这不起作用。我也尝试过使用NSAttributedString。

NSMutableAttributedString *attMyString = [NSMutableAttributedString alloc] initWithString: myString];
[attMyString setAttributes: textAttributes range: NSMakeRange(0, [attMyString lenght])];
[attMyString drawAtPoint: thePoint];

任何建议将不胜感激。

再次,我可以更改字体大小和颜色,以便所有内容都正确链接-我无法证明其正确性。

objective-c macos cocoa appkit
1个回答
0
投票

thePoint位于单元格的左侧,因此drawAtPoint将在单元格的左侧绘制。 drawInRect将做您想要的。

© www.soinside.com 2019 - 2024. All rights reserved.