[英]how to make the first line of label in the same centre position of another UIView
[英]How to make Label first line text less from other line
AFAIK UILabel
沒有此功能,但是您可以通過使用UITextView實現此行為。 您可以將其調整為看起來像您的標簽,然后為其文本容器設置排除路徑,如下所示:
let exclusionPath = UIBezierPath(rect: textView.convert(button.frame, from: button.superview))
textView.textContainer.exclusionPaths = [exclusionPath]
如果您還想根據第一行中的可用寬度來更改按鈕的寬度,那么您可以設置最小寬度(根據文本寬度和按鈕中的插入項)的排除路徑框架,然后像這樣計算第一行中的可用空間在此答案中提到(它顯示了如何計算最后一行的寬度,但對第一行進行相同的操作非常相似)
只需嘗試此代碼,它將對您有所幫助
myMutableString = NSMutableAttributedString(string: myString, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!])
myMutableString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSRange(location:2,length:4))
myMutableString.addAttribute(NSFontAttributeName, value: UIFont(name: "SFUIText-Bold", size: 14)!, range: NSRange(location:2,length:4))
labName.attributedText = myMutableString
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.