OGeek|极客世界-中国程序员成长平台

标题: ios - 当 pointSize 为 0 时,UIFont 没有设置正确的字体名称 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:22
标题: ios - 当 pointSize 为 0 时,UIFont 没有设置正确的字体名称

为什么UIFont在大小设置为零时会错误地打印出字体名称? 当我将大小设置为大于零的任何值时,就会输出正确的字体名称。这种行为背后是否有特殊原因,或者这是一个真正的错误。

UIFont* f1 = [UIFont fontWithName"HelveticaNeue-Thin" size:0];
NSLog(@"%@",f1);
UIFont* f2 = [UIFont fontWithName"HelveticaNeue-Thin" size:1];
NSLog(@"%@",f2);

输出:

<UICTFont: 0x7fb90c988e10> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 0.00pt
<UICTFont: 0x7fad92177a90> font-family: "HelveticaNeue-Thin"; font-weight: normal; font-style: normal; font-size: 1.00pt



Best Answer-推荐答案


the documentation :

fontSize The size (in points) to which the font is scaled. This value must be greater than 0.0.

您正在尝试实现不受支持的行为。预期会出现“不正确”的结果。

关于ios - 当 pointSize 为 0 时,UIFont 没有设置正确的字体名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30533806/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4