我是xcode新手,需要在UILabel中找到字符串的字符数
@IBAction func buttonPressed(_ sender: Any) {
curr_channel.text = ""
let tag = (sender as! UIButton).tag
if((curr_channel.text?.character.count())! < 2){
curr_channel.text = curr_channel.text! + String(tag)
}
}发布于 2020-02-10 18:03:28
我想这就是你需要的:
@IBAction func buttonPressed(_ sender: Any) {
let tag = (sender as! UIButton).tag
if let text = curr_channel.text, text.count < 2 {
curr_channel.text = "\(text) \(tag)"
}
}发布于 2020-02-09 19:11:05
下面是如何在UILable中打印/获取字符数的方法。
@IBOutlet weak var myLabel: UILabel!
@IBAction func buttonPressed(_ sender: Any) {
let countOfCharsInLabel = myLabel.text?.count
print("\(countOfCharsInLabel)")
}https://stackoverflow.com/questions/60134484
复制相似问题