美文网首页
Ios 点击按钮生成随机数

Ios 点击按钮生成随机数

作者: 人鱼小姐没有腿 | 来源:发表于2019-07-31 17:30 被阅读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)"
    }
    

    }

    相关文章

      网友评论

          本文标题:Ios 点击按钮生成随机数

          本文链接:https://www.haomeiwen.com/subject/xmetdctx.html