【发布时间】:2015-10-17 07:37:18
【问题描述】:
这是正文:
@IBOutlet weak var legalText: UITextView!
let textToAppend = "TERMS OF SERVICE\nLast Updated: May 7, 2015\n\nPLEASE NOTE: The HIGO Terms of Service as stated below is effective as of the 'Last Updated' date above for any user who is browsing the HIGO website, or for any user who creates a HIGO account on or after that date."
legalText.text = legalText.text.stringByAppendingString(textToAppend)
我想加粗“服务条款”和“请注意:以下 HIGO 服务条款自上述“最后更新”日期起对任何浏览 HIGO 网站的用户或任何用户生效谁在该日期或之后创建了 HIGO 帐户。”
我尝试在 uitextview 中以编程方式使用 uilabel,但没有奏效:
var termsofservice : UILabel = UILabel()
termsofservice.numberOfLines = 0
termsofservice.text = "TERMS OF SERVICE"
termsofservice.font = UIFont.boldSystemFontOfSize(20)
termsofservice.textAlignment = NSTextAlignment.Left;
var pleasenote : UILabel = UILabel()
pleasenote.numberOfLines = 0
pleasenote.text = "PLEASE NOTE: The HIGO Terms of Service as stated below is effective as of the 'Last Updated' date above for any user who is browsing the HIGO website, or for any user who creates a HIGO account on or after that date."
pleasenote.font = UIFont.boldSystemFontOfSize(20)
pleasenote.textAlignment = NSTextAlignment.Left;
let textToAppend = "\(termsofservice)\nLast Updated: May 7, 2015\n\n\(pleasenote)"
也尝试使用这些但没有用,它只显示“服务条款”和“上次更新..”,没有显示“请注意...”
var termsofservice = "TERMS OF SERVICE"
var normalText = "\n\nLast Updated: May 7, 2015"
var pleasenote = "\n\nPLEASE NOTE: The HIGO Terms of Service as stated below is effective as of the 'Last Updated' date above for any user who is browsing the HIGO website, or for any user who creates a HIGO account on or after that date."
var attributedString = NSMutableAttributedString(string:normalText)
var attrs = [NSFontAttributeName : UIFont.boldSystemFontOfSize(15)]
var boldString = NSMutableAttributedString(string:pleasenote, attributes:attrs)
var boldString0 = NSMutableAttributedString(string:termsofservice, attributes:attrs)
boldString0.appendAttributedString(attributedString)
attributedString.appendAttributedString(boldString)
legalText.attributedText = boldString0
如何将那部分字符串加粗?
注意:文本仍然很长,并且有更多部分字符串要加粗。
【问题讨论】:
-
你应该使用属性字符串
-
怎么样?请给我看。
-
当然,您的第二个代码不会显示出令人愉快的部分。您将其附加到错误的字符串。
-
attributedString.appendAttributedString(boldString)到boldString0.appendAttributedString(boldString)
标签: swift uitextview