Splitting text into cards

Let me explain the idea. Let's say the text and title comes from the Internet. The text takes up more space than one page shown in the gif. How to make automatic generation of cards to fully fit the text, also taking into account the size of the device (that is, smaller phones will have more cards, because there will be fewer cards). Also, the title must appear once on the first card. The last card may be half empty, if that happens. How can such an algorithm be implemented? Please, help me.
SwiftUI or UIKit is welcome.
So, I was not the only one who was not understood. 😉

Did I explain myself incomprehensibly?

somehow. As you do not explain what you don't understand.
Did you look at the algorithm I proposed ? Did you try to implement (it requires basic Swift, not advanced UIKit or SwiftUI skills).

I just don't really understand what the input is.

Which input are you speaking about ? The input text you want to split ? The messages on the forum?
Your answers are not clarifying your problem in anyway.
I will try to implement your algorithm if I understand it. I'll write if I was able to do it or not after trying.
Splitting text into cards
 
 
Q