使用MMMarkdown,只有系统字体会显示粗体或斜体文本

时间:2014-12-09 10:00:57

标签: ios swift fonts markdown

我正在使用MMMarkdown,当我没有将字体应用于UILabel或UITextView时(我必须保留UITextView以便TTTAttributedLabel不会这样做),所有降价都可以。当我给标签或textview一个字体时,我只能获得降价超链接才能工作。我尝试切换到AttributedMarkdown库,但超链接完全不适用于那个。

在我的Markdown课程中:

class Markdown: NSObject {

func markdownString(stringForVideoDescription:NSString) -> NSMutableAttributedString {
    var options = [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType]

    var error:NSError?

    var markdown:NSString = stringForVideoDescription
    var html:NSString = MMMarkdown.HTMLStringWithMarkdown(markdown, error: &error)

    var markdownAttributedString:NSMutableAttributedString = NSMutableAttributedString(data: html.dataUsingEncoding(NSUTF32StringEncoding)!, options: options, documentAttributes: nil, error: &error)!

    if let font: UIFont = UIFont(name: "Marion-Regular", size: 14) {
        markdownAttributedString.addAttributes([NSUnderlineStyleAttributeName:NSUnderlineStyleAttributeName], range: NSMakeRange(0, markdownAttributedString.length))
    }

    println(html) // used to see that markdown is in fact working

    return markdownAttributedString

}

在我看来,我实际上是从json api中拉出来的,但是我替换为测试:

let bodyText = "\*This* sample \[I'm an inline-style link](https://www.google.com)"

myTextView.attributedText = Markdown().markdownString(bodyText)

我是否需要设置css来为每个粗体斜体文本指定字体?非常感谢任何帮助,因为我的设计师不想使用Times New Roman的默认字体。

0 个答案:

没有答案