简体   繁体   中英

Add multiple UITextView programmatically

I am trying to display an article in a ViewController.

The output that I receive from the API divides the article into paragraphs, and each paragraph is a node in the JSON. For example,

{
 "para" : 1,
 "content" : "some long paragraph"
},
{
 "para" : 1,
 "content" : "some long paragraph"
}

I want to display this content as one long article, but I want to let each paragraph to be viewed in one textView instead of combining all the paragraphs and view in one textView.

I am on Xcode 8, Swift 3. I use Cocoapods, so libraries are welcome.

If you want to use Text view , then you don't need to create multiple textview. Just use a single textview.

Use a for loop on your response object and append all the paragraph's content in a single string using /n after each paragraph. And then simply set that string value into textview. That's it. I hope it will work for you better..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM