在 SwiftUI 中使部分文本加粗
问题描述:
我想知道如何仅将文本的一部分设为粗体,同时在 SwiftUI 中保持其余部分常规".
I was wondering how I would make only sections of a text bold while keep the rest 'regular' in SwiftUI.
我目前拥有:
Text("Coronavirus Disease of 2019")
并且我希望它打印出 COronaVirus Disease of 2019 并且没有'只能将某些部分加粗.
and I want it to print out COronaVirus Disease of 2019 and haven't been able to get only some parts bold.
答
Swift 5.5
Foundation 支持 Markdown.
Swift 5.5
Foundation supports Markdown.
在要加粗的字符周围添加双星号 (**).
Add double asterisks (**) arroud the characters that you want to make bold.
Text("**CO**rona**V**irus **D**isease of 20**19**")
在要斜体的字符周围添加下划线.
Add underscore arround the charachters that you want to make italic.
Text("Is this text _emphasized_?")