The goal is for me to have a List section with a bold header and non-bold sub-header, which is something I couldn't figure out how to do. So I tried making the header with a Text view that contains text that is partially bold, and partially normal non-bold text.
I tried doing this with an NSAttributedString which works with a UILabel but it doesn't appear to work with swiftUI's Text object.
Im making the header like so:
Section(header: Text(docSection.formattedHeader)) {
    ...
where docSection.formattedHeader is an NSAttributedString that is half bold, half non-bold separated with a \n
however then I get the following error:
Initializer 'init(_:)' requires that 'NSAttributedString' conform to 'StringProtocol'
Is there anyway to achieve this?
Since NSAttributedString is incompatible with SwiftUI (yet), you should use Text instead. But for Section, You can use any View in. So why don't you use a stackView like this:
Section(header:
    VStack(alignment: .leading) {
        Text("Header").fontWeight(.bold)
        Text("Subheader").fontWeight(.regular)
    }
) {
    Text("Content")
}
Also you can use HStack or any other combined views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With