我有一个 UILabel,每次单击按钮时它都会动态更新,数据将从 firebase 获取并显示在 uilabel 上。我能够显示如下所示的文本。我想在文本中遇到特定的分隔符(比如'.'句号)时插入一个换行符。我已经研究了许多关于 UIlabel 换行符的解决方案,但找不到我正在寻找的解决方案,每个解决方案都处理我们在 Storyboard本身中提供的静态文本。任何帮助将不胜感激。谢谢。 )
最佳答案
为标签创建了一个导出,并采用了一个由“.”分隔的三个句子的字符串。附加图像中的内容将是这个字符串。尝试使用下面给出的 replacingOccurences() 函数。
@IBOutlet weak var trialLabel: UILabel!
var string = "This is a trial text.Let us jump to a new line when the full stop is encountered.Hope it helps."
string = string.replacingOccurrences(of: ".", with: ".\n")
trialLabel.text = string
检查 https://developer.apple.com/documentation/foundation/nsstring/1412937-replacingoccurrences供进一步引用。快乐编码!!
关于ios - 找到特定字符时为 UILabel 文本插入换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49520023/