[英]Swift filling textView
How can I fill my textView with restraints so that each string "test" print all the way down the textView. 如何用约束填充textView,以便每个字符串“ test”在textView下方一直打印。 Example in the picture. 图片中的示例。
-Trying to match "Test" with percentages. -尝试将“测试”与百分比进行匹配。
for _ in 1...100{
profitLoss.text = "Test\n"
}
you have to add each string to previous string, run this code in swift play ground it will help you to understand. 您必须将每个字符串添加到先前的字符串,然后在快速的环境中运行此代码,这将有助于您理解。
var finalString = "1%"
for i in 2...100 {
finalString += "\n\(i)%"
}
print(finalString)
profitLoss.text = finalString
Build your string first, then set it to the textView's text: 首先构建您的字符串,然后将其设置为textView的文本:
var test = "Test"
for _ in 1...99 {
test += "\nTest"
}
profitLoss.text = test
It's not good way as per your image that attached but you can achaive it by below 根据所附加的图像,这不是一种好方法,但是您可以在下面将其禁用
var strText = "Text \n"
for _ in 1...100 {
txtView.text = strText.appending(strText)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.