Objective-C:均匀显示 NSString
如果我循环遍历一堆字符串并想说以编程方式将它们用作 NSTextField 的 stringValue 或 NSButton 的标题,是否有一种方法可以确定文本字段或按钮的框架以及之间的间距所需的长度...我知道这与为每个字体选择的字体有关,但如果我可以动态计算出 NSString.length = x 像素,那就太好了。有什么想法吗?
If I am looping through a bunch of strings and want to say use them as the stringValue of a NSTextField or title of a NSButton programmatically is there a way to determine the length I will need for the frame of the textfield or buttons and the spacing between...I know this is kind of relevant to the font selected for each but it would be great if I could dynamically figure out NSString.length = x pixels. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 NSString 上的 sizeWithFont 方法。
CGSize 具有您可以检查的高度和宽度。
Look into the sizeWithFont method on NSString.
CGSize has a height and width that you can then examine.