Objective-C:均匀显示 NSString

发布于 2024-12-28 05:38:08 字数 176 浏览 1 评论 0原文

如果我循环遍历一堆字符串并想说以编程方式将它们用作 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第几種人 2025-01-04 05:38:08

查看 NSString 上的 sizeWithFont 方法。

CGSize size = [mystring sizeWithFont:myfont];

CGSize 具有您可以检查的高度和宽度。

Look into the sizeWithFont method on NSString.

CGSize size = [mystring sizeWithFont:myfont];

CGSize has a height and width that you can then examine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文