更改NSTextField字体大小以适应 [英] Change NSTextField font size to fit

查看:495
本文介绍了更改NSTextField字体大小以适应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么像UILabel的> AdjustFontSizeToFitWidth 可以用于NSTextField吗?

解决方案

总之:不。您必须进行一些强力工作,以确定字符串 - sizeWithAttributes: - boundingRectWithSize:options:attributes: >

我将从一个标准的系统字体大小开始,然后从那里开始向下或向上,取决于它是小于还是大于所需的矩形。


Is there anything like the UILabel's adjustsFontSizeToFitWidth that can be used with a NSTextField?

解决方案

In short: no. You have to do some brute force work to determine a string's -sizeWithAttributes: -boundingRectWithSize:options:attributes: with a given font size (set as an NSFont for NSFontAttributeName).

I'd start with a standard system font size and work down or up from there, depending on whether it's smaller or larger than the desired rectangle.

这篇关于更改NSTextField字体大小以适应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆