Skip to content

Instantly share code, notes, and snippets.

@eldaroid
Last active August 10, 2024 21:23
Show Gist options
  • Save eldaroid/3e4daf1a0547c2c0338a66444a60cbfb to your computer and use it in GitHub Desktop.
Save eldaroid/3e4daf1a0547c2c0338a66444a60cbfb to your computer and use it in GitHub Desktop.
Динамическое окрашивание текста: 1) Встроенным текстовым стилированием; 2) AttributedString
struct DynamicTextColoring: View {
var body: some View {
VStack {
// только с 16 оси
Text("1) Коллеги и платформа \(Text("поздравляют Вас").foregroundColor(.teal))!")
Text(attributedCongratulationString)
}
}
var attributedCongratulationString: AttributedString {
var attributedString = AttributedString("2) Коллеги и платформа поздравляют Вас!")
attributedString.foregroundColor = .primary
if let range = attributedString.range(of: "поздравляют Вас") {
attributedString[range].foregroundColor = .teal
}
return attributedString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment