Fra*_*nck 16 xcode nsattributedstring custom-font swift
我有UITextView一些来自.rtf的文本(直接粘贴到Xcode上)
上下文只包含一种自定义字体(Futura Book BT 11.0)
如果我将"text(attribution)"属性设置为"plain"=自定义字体从故事板和应用程序中正确显示
如果我将"text"属性设置为"attribution"=.自定义字体从故事板正确显示但不是从应用程序.
由于我的目标是使用多种字体工作的文本,如何使属性属性与自定义字体一起使用?(迅速)
谢谢!
自定义字体从故事板正确显示但不是从应用程序.
应用程序根本不显示字体,还是还原为系统字体?如果它恢复到Helvetica,看起来这可能是iOS 8.1中的已知错误 http://openradar.appspot.com/radar?id=5117089870249984
可能的解决方案: 您是否在模拟器和设备上进行了测试?它可能只是在模拟器上不起作用,这意味着您可以通过在系统上安装字体来修复它.
小智 5
当我在属性UILabel中使用多种自定义字体时,遇到了同样的问题。情节提要显示正确的结果,但设备未显示!
我发现如果字体大小与具有不同自定义字体的文本不同。效果很好!
所以现在我使用字体大小略有不同。就像一个是14,我为另一个使用了14.01。在情节提要板内部是不可能的,因此我将情节提要板作为源代码打开并手动设置字体大小,例如:
<attributedString key="attributedTitle">
<fragment content="Do not have account? ">
<attributes>
<color key="NSColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="calibratedRGB"/>
<font key="NSFont" size="14" name="Roboto-Light"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
<fragment content="Login">
<attributes>
<color key="NSColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="calibratedRGB"/>
<font key="NSFont" size="14.01" name="Roboto-Bold"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
<attributedString key="attributedTitle">
Run Code Online (Sandbox Code Playgroud)
但是我仍然找不到原因。
我做什么:
private var _mutableString: NSMutableAttributedString!
if !isTitle {
var titleFont: UIFont = UIFont(name: StyleGlobals.TitleFontName, size: StyleGlobals.TitleFontSize)!
self._mutableString.addAttribute(NSFontAttributeName, value: titleFont, range: NSMakeRange(0, count(self._mutableString.string)))
self._mutableString.addAttribute(NSForegroundColorAttributeName, value: StyleGlobals.FontColor, range: NSMakeRange(0, count(self._mutableString.string)))
}
self.Label.attributedText = self._mutableString
Run Code Online (Sandbox Code Playgroud)
这将应用新的字体颜色以及字体本身。我有一个特定的 UILabel 必须能够包含不同的字体。它可以是标题或副标题。因此,当我确定标签将包含什么内容时,我必须应用字体。
| 归档时间: |
|
| 查看次数: |
8808 次 |
| 最近记录: |