[英]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. 我刚开始使用swift和Xcode并一直在开发一个应用程序。 Right I have no idea how to print a variable in the UI. 是的,我不知道如何在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.