簡體   English   中英

UILabel:adjustsFontSizeToFitWidth 不起作用

[英]UILabel: adjustsFontSizeToFitWidth doesn't work

我想制作一個適合標簽大小的字符串。 下面的代碼不會改變任何東西。 我究竟做錯了什么?

nameLabel.font = UIFont.systemFont(ofSize: 30)
nameLabel.adjustsFontSizeToFitWidth = true
nameLabel.text = "fjggfjghggiuhgughuohgoihiohiohiughiugyiugyu8ftufuyguoy80houhuiy78rt6drtyreruti"
nameLabel.numberOfLines = 1
nameLabel.minimumScaleFactor = 0.5

UIKit 需要提示您需要多少行文本,否則它不知道要縮小多少。 如果您希望整個文本適合一行的標簽,您還需要: nameLabel.numberOfLines = 1

工作操場示例:

import Foundation
import UIKit

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
label.numberOfLines = 1
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5
label.text = "Some very long text goes here"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM