2017-05-31 117 views
-1

链接和不同的字体样式我一直在努力实现这一目标:字符串与斯威夫特3

基本上是:一个非常简单的文本行包括2个链接。当文本的其他部分处于常规状态时,这两个链接处于半角状态。

正试图使用​​故事板将所有内容都完成到同一个字符串中。

令人惊讶的是,它似乎很难实现。我无法理解为什么那么简单应该如此艰难。期待实现这一目标的故事板视图...

Please view the images by clicking this link

谢谢大家的帮助!

昆汀

回答

1

我不能帮你的故事板,但您可以通过编程这样来做:

先为您的标签现在

yourLabel: UILabel = 
{ 
    let label = UILabel() 

    return label 
}() 

,有一些文字加粗其余不是,你需要声明一个NSMutableAttributedString,然后将它附加到另一个字符串上,如下所示:

yourLabel: UILabel = 
{ 
    let label = UILabel() 

    let attributedText = NSMutableAttributedString(string: "Your Text Here", attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 14)]) 

    attributedText.append(NSAttributedString(string: "Your Bold Blue Text Here", attributes: [NSForegroundColorAttributeName: UIColor.blue, NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14)])) 

    label.attributedText = attributedText 

    return label 
}() 

您现在可以将其中一个字符串设置为链接/按钮,而另一个则不可以。

希望它有帮助。