简体   繁体   中英

How do I display text that will vary (in Xcode with Swift)?

I just started with swift and Xcode and have been working on an app. Right I have no idea how to print a variable in the UI. I understand how to use Labels for static text but need to print numbers that are going to vary based on user input.

You can use string interpolation to create strings from numbers. Then assign to your label.

var myNum: Int = 5
var myString = "The number is \(myNum)"
myLabel.text = myString

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM