2017-04-16 82 views
-2

arc4random我有代碼IBOutlet中與swift3.0

class ViewController: UIViewController { 

var detailText: String = "Chance of win is 50%" 

@IBOutlet weak var winChance: UILabel! 

func someMethod() -> Void { 
    print("Method called!") 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 
self.winChance.text = self.detailText 
} } 

我怎樣才能使這個50%arc4random? 如果我用「(VAR)」的東西卻是不由你想要的標籤文字是我 日Thnx

+0

'取勝的機會是「randomnubmer」'? – JuicyFruit

+0

是............ –

回答

0

試試這個

class ViewController: UIViewController { 

    @IBOutlet weak var winChance: UILabel! 

    func someMethod() -> Void { 
     print("Method called!") 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     let randomNumber = Int(arc4random_uniform(100)) 
     self.winChance.text = "Chance of win is \(randomNumber)%" 
    }  
}