iOS Swift UILabel 将两行显示为单行

标签 ios swift uitextfield uilabel

<分区>

在我的应用程序中,我遇到了一个麻烦,我的要求是我想在单行中显示文本,但是来自 API 的响应如下:

"Hi
Hello
How Are You"

如何转换它并在 UILabel 中以单行显示

最佳答案

var newString = myString.components(separatedBy: CharacterSet.newlines).joined(separator: " ")

然后您可以将该新字符串绑定(bind)到 UILabel。

关于iOS Swift UILabel 将两行显示为单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50408223/

相关文章:

ios - NSDictionary 检查 ios10 中的 "<null>"值

iOS - UIView setCenter 在 UIView animateWithDuration 中不起作用

ios - 理解 swift 3 中的平等?

ios - Swift 字典的 Swift 数组

ios - 仅适用于 pod 文件夹的 Swift Auto Documentation jazzy

ios - UITextFieldDelegate textFieldShouldReturn 调用者

iphone - 如何强制用户停留在特定的 UITextfield

ios - Swift 不从 Objective-C header 导入 typedef

ios - 在 Swift 中,使用选择器 init 覆盖的方法具有不兼容的类型

ios - 阻止 UITextField 安全文本清除现有文本