UILabel 在输入一些文本后显示点
UILabel shows dot after typing some texts
我有一个在 UIToolbar 中实现的 UILabel 来显示文本计数。
问题是如果用户开始输入并且文本数达到 10 个以上,标签会显示点点点。
有办法解决这个问题吗?下面是我的标签代码
let textCountLabel: UILabel = {
let lb = UILabel()
lb.text = "0/2000"
lb.textColor = .lightGray
lb.sizeToFit()
return lb
}()
func createToolBar(){
let toolBar = UIToolbar()
toolBar.sizeToFit()
var items = [UIBarButtonItem]()
items.append(
UIBarButtonItem(customView: anonymousButton)
)
items.append(
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
)
items.append(
UIBarButtonItem(customView: textCountLabel)
)
toolBar.setItems(items, animated: true)
textFieldPost.inputAccessoryView = toolBar
}
当您更新 textCountLabel 时,也会更新大小或字体以适应预定义 space 中的文本。查看示例代码。
textCountLabel.text = yourUpdatedString
textCountLabel.sizeToFit()
我有一个在 UIToolbar 中实现的 UILabel 来显示文本计数。
问题是如果用户开始输入并且文本数达到 10 个以上,标签会显示点点点。
有办法解决这个问题吗?下面是我的标签代码
let textCountLabel: UILabel = {
let lb = UILabel()
lb.text = "0/2000"
lb.textColor = .lightGray
lb.sizeToFit()
return lb
}()
func createToolBar(){
let toolBar = UIToolbar()
toolBar.sizeToFit()
var items = [UIBarButtonItem]()
items.append(
UIBarButtonItem(customView: anonymousButton)
)
items.append(
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
)
items.append(
UIBarButtonItem(customView: textCountLabel)
)
toolBar.setItems(items, animated: true)
textFieldPost.inputAccessoryView = toolBar
}
当您更新 textCountLabel 时,也会更新大小或字体以适应预定义 space 中的文本。查看示例代码。
textCountLabel.text = yourUpdatedString
textCountLabel.sizeToFit()