Show more button next to end of text Swift

2020-03-03 09:10发布

问题:

I want to show more button at the end of the text or below if there isn't enough space. I don't understand how Apple developers did this? Please answer in swift. After clicking on more button i want to show all the text. change the button to less.

Thanks in advance.

回答1:

Here's a great CocoaPod for the functionality you're looking for.

https://github.com/ilyapuchka/ReadMoreTextView

This will allow you to set a maximum number of lines and customise the text append to the end of the trimmed text. You can change the font and color since it is an NSAttributedString.



回答2:

If you add more than 4-5 view controllers to a TabBar Controller, either in storyboard or programmatically(adding array of controllers to a tabar controller), it automatically show a more item as a tabar item in TabBar.



回答3:

I think, what you what to know is how to have more than 5 View Controllers as tabs in a Tab Bar Controller.

By default a Tab Bar Controller can accommodate 5 View Controllers' connection, but when it goes more than 5 View controller, at the 5th Tab, it creates a list of options that will accommodate the extra view controllers.

First take a View Controller and embed it under a Tab Bar Controller by going to Editor menu like-

Editor->Embed In-> Tab Bar Controller

Then drag another View Controller and from the Tab Bar Controller Control drag on that new View Controller like -

And Select the View Controllers under the "Relationship Segue".

Now we have something like -

The tab bar names look ugly. So, let's change that.Select the star icon for a View Controller and then in the identity inspector change the Title like-

Let's run it and se how it looks like -

Now let drag and drop 7 5 more View Controller and Name them Tab 3, Tab 4, Tab 5, Tab 6, and Tab 7 respectively. Connect them the same way with Relationship Segue. Here, I changed the color of the views under each View Controller to detect the changes easily.

Let's Run it now-

When we click on the More Tab, we see this-

Basically after the 5th View Controller, all went under the last Tab but not in a tabbed way.

Select each view controller under the list and it will take you to the linked View Controller that was done earlier.

If you want to see all the View Controller, click Edit at top and you will see something like -

Hope that's what you asked and it helps.