简体   繁体   English

如何显示变化的文本(在带有Swift的Xcode中)?

[英]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.

相关问题 使用 SwitftUI,我如何改变文本的字体大小? - Using SwitftUI, how do I vary the font size of a Text? 如何使用Firebase数据库通过Xcode / Swift在表视图中显示多个路由/子级 - How do I use Firebase Database to display multiple routes/childs in Table View using Xcode/Swift Swift xcode:如何在与文本字段和按钮列表相同的视图上绘制? - Swift xcode: How do I draw on the same view as a text field plus a list of buttons? Xcode 4.5:如何修复我的文本视图,以便它们在iPad上以纵向和横向模式正确显示? - Xcode 4.5: How do I fix my text views so they display properly in portrait and landscape mode on an iPad? 如何快速将图像显示为表情符号? - How do i display an image as a emoji in swift? 如何在Swift 3中显示MKCircle - How do I display MKCircle in Swift 3 当按下按钮时,如何获得显示随机文本的标签? [迅速] - How do I get a label to display random text when a button is pressed? [Swift] Xcode / Swift:显示我添加到CocoaPod的“打印” - Xcode/Swift: Display “print” that I added to CocoaPod 如何在Swift 2 / XCode 7中的UIButton上设置等效的键? - How do I set a key equivalent on a UIButton in swift 2/XCode 7? 如何使用Xcode 6(Swift)添加引脚(注释) - How Do I add Pins (Annotations) with Xcode 6 (Swift)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM