[英]Have half a UILabel text bold and half not?
我希望UILabel
的text
一半加粗,另一半不加粗。 我怎樣才能做到這一點?
NSAttributedString允許在字符串中指定格式,但是遺憾的是,UIKit對此還沒有做任何事情。 但是,有一些開放源代碼實現。 簽出OHAttributedLabel 。
除非您將UILabel子類化並弄混了子視圖,否則您將很難做到這一點。 最好改用兩個UILabel。 在這里找到關於它的另一個線程 。
UILabel具有采用NSAttributedString
attributedText
,該NSAttributedString
允許您自定義字符串的多個方面,包括更改字體類型和其他屬性
var attributedString = NSMutableAttributedString(attributedString: NSAttributedString(string: "Not Bold"))
let boldAttrString = NSAttributedString(string: "BOLD", attributes: [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 15)!])
attributedString.appendAttributedString(boldAttrString)
myLabel.attributesText = attributedString
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.