繁体   English   中英

属性标题未在xib文件的UIButton中加载自定义字体

[英]attributed title not loading custom font in UIButton in xib file

我在这个问题上全神贯注,无法找出问题所在。 我的一个界面生成器xib中有一个按钮,该按钮具有标题的属性字符串,该标题使用添加到我的应用程序中的自定义字体。 在界面生成器中,一切看起来都很好。

我100%确信我已将字体(Montserrat)正确加载到我的应用程序中。 我可以在代码中以及控件的非属性标题中正确使用它,并且效果很好。 我还检查了调试器,并正确列出了字体:

(lldb) po [UIFont familyNames]

<__NSCFArray 0x7bb34e20>(
Thonburi,
...
Montserrat,
...
Bodoni 72 Smallcaps
)

(lldb) po [UIFont fontNamesForFamilyName:@"Montserrat"]

<__NSCFArray 0x7be75400>(
Montserrat-Regular,
Montserrat-Bold
)

我还可以在文本编辑器的xib文件中看到,看起来它应该为单词“ got”加载Montserrat:

                        <state key="normal">
                            <attributedString key="attributedTitle">
                                <fragment content="Already ">
                                    <attributes>
                                        <color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                        <font key="NSFont" size="15" name="Helvetica"/>
                                        <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
                                    </attributes>
                                </fragment>
                                <fragment content="got">
                                    <attributes>
                                        <color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                        <font key="NSFont" size="15" name="Montserrat-Bold"/>
                                        <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
                                    </attributes>
                                </fragment>
                                <fragment content=" an account? ">
                                    <attributes>
                                        <color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                        <font key="NSFont" size="15" name="Helvetica"/>
                                        <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
                                    </attributes>
                                </fragment>
                                <fragment content="SIGN IN!">
                                    <attributes>
                                        <color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                        <font key="NSFont" size="15" name="Helvetica-Bold"/>
                                        <font key="NSOriginalFont" size="15" name="Helvetica-Bold"/>
                                        <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
                                    </attributes>
                                </fragment>
                            </attributedString>
                        </state>

但是我可以看到iOS在单词“ got”中用“ HelveticaNeueInterface-Regular”替换了“ Montserrat-Bold”的用法。 这是调试器的另一段摘录:

(lldb) po [self signInButton].titleLabel.attributedText

Already {
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb41430> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
}got{
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb3ffe0> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
} an account? {
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb41430> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
}SIGN IN!{
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb3f6a0> font-family: \"Helvetica\"; font-weight: bold; font-style: normal; font-size: 15.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";

}

在UILabels,模拟器或设备,iOS 7或8上似乎也发生了同样的问题。但是我可以在没有属性的标题上使用Montserrat。 在这一点上,我真的很沮丧。 有人遇到过这个问题吗?

谢谢Omri

我认为这是一个错误

遇到了这个雷达http://openradar.appspot.com/18716979

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM