Group Group Group Group Group Group Group Group Group

Is markdown possible in a UITableView footer's title?

Is it possible to have some words on a grouped Table View footer in bold?
Other way to word the question: is it possible to easily apply markdown to a String in a Table View footer?

I have a table view with 16 sections and I have an array of Strings that is going to feed the titleForFooterInSection method with a simple return footers[section] call.

The result I would like to achieve is the one you can see on iPhone in Settings > Accessibility > Zoom. Some bold words, some lists…
Someone suggested me to make a custom UIView and then return it, but this would require 16 different views, with huge and slow method calls … I would like to believe that there is an easier way.

Also, I would like to keep the app accessible, that is if the user increases the size of the text in accessiblity I cannot use .systemFont(ofSize: 16, weight: .bold) because it will not scale. On the other hand, if I use preferredFont(for:) it will not have neither a range to select nor a bold option… So confusing!
For what I have tried it seems I should use an NSMutableAttributedString to change the text to bold and then an NSAttributedString for the whole thing but … titleForFooterInSection wants Strings and will probably loose all the formatting … damn!

Can someone enlighten me on this?
Thank you so much!

@notationmaster Do you still have issues with this?

Yes absolutely … I cannot create multiple views for each word that I want with a different font weight.
Apple seems to use a form of Markdown and I would like to learn how to do that.
Thanks

Hi @notationmaster,
I believe the advice provided to you is correct. You need to use the titleForFooterInSection call, set your string in an array of 16 items and then create a view, create a label and set the attributedText of that label to the text you want. Since you want everything so simple and easy, you will have to also write a small parser that takes the string and parses tags or token in the string and convert them into attributed text, like bold, italics, color etc.

cheers,

Thank you @jayantvarma!
I got lost after the creation of the view and the label … the parsing part was totally obscure to me.
Could you explain it to me or point me towards a tutorial where I could learn how to do what you are suggesting?

Finally: shouldn’t I use viewForFooterInSection instead of titleForFooterInSection?
If not, how should I return a view from a method that returns a string?

Hi @notationmaster,
sorry I meant viewForFooterInSection, where you create the view, then add the UILabel and assign the attributedtext to the label.

Parsing - you can create a string like

This is bold and this is $italics$

this is NOT markdown, but your own tags on what you want, you could also use a markdown library that would parse the markdown text and give you an attributed string.

cheers,

Thank you @jayantvarma. I am flattered by how high a consideration of my knowledge you have but … unfortunately … I have no idea how to realise what you suggest.

Could you please explain it to me in a thorough way? Please, assume that all I know is what gotten out from the Beginning Table Views tutorial here.

Thanks!

Hi @notationmaster,
I would suggest that you look at (Google) Markdown, there are several libraries for Swift that parse markdown for you. That is the easiest way to get your attributed text. There are also some more 3rd party libraries (I am missing the name off the top of my head) that allow you to create AttributedText directly. However, if you are starting out with development, I would recommend that you solve things in smaller chunks, so first get the footer resolved, then try to learn about attributedText, then try to add that to teh footer, that way you will not only get a solution but also learn something that will last.

cheers,

Thank you very much!
It is enough to know that there is not a native Apple solution for what I am looking for.
I will keep building the app piece by piece and eventually add that feature.
Thanks