Last active
October 7, 2024 19:00
-
-
Save eldaroid/3e4daf1a0547c2c0338a66444a60cbfb to your computer and use it in GitHub Desktop.
RU: Динамическое окрашивание текста: 1) Встроенным текстовым стилированием; 2) AttributedString EN: Dynamic text colorization: 1) Built-in text styling; 2) AttributedString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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