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!
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.
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?
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.