Ios 点击按钮生成随机数

2019-07-31  本文已影响0人  人鱼小姐没有腿

class ViewController: UIViewController {

var index1 = 0 ;
var index2 = 0 ;
let numString = "数字为:"


@IBOutlet weak var num1: UITextView!
@IBOutlet weak var num2: UITextView!
@IBAction func rollbutton(_ sender: Any) {
   updateText()
    
}
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
       updateText()
}

func updateText(){
    index1 = Int.random(in: 1...6)
    index2 = Int.random(in: 1...6)
    
    print(index1)
    print(index2)
    
    num1.text = "\(numString) \(index1)"
    num2.text = "\(numString) \(index2)"
}

}

上一篇下一篇

猜你喜欢

热点阅读