Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Xcode 7 和 swift 中,我有一个标签,它生成一个介于 0 - 50 之间的随机数,但是当它生成一个零时,我希望它显示数字 1。我需要添加什么代码才能做到这一点?
label1TextLabel.text = String(arc4random_uniform(51))
问候。
德尔
写下这段代码:
var number = Int(arc4random() % UInt32(51)) if number == 0 { number = 1 } label1TextLabel.text = "\(number)"