-
-
Save d2burke/feb86dda6832076f4497c9268ee1cde4 to your computer and use it in GitHub Desktop.
Swift v. SwiftUI Attributed Strings
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
// Swift Attributed Strings | |
let quote = "Holy fucking shit" | |
let firstAttributes: [NSAttributedString.Key: Any] = [.backgroundColor: UIColor.green, NSAttributedString.Key.kern: 10] | |
let secondAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red] | |
let firstString = NSMutableAttributedString(string: "Holy ", attributes: firstAttributes) | |
let secondString = NSAttributedString(string: "fucking ", attributes: secondAttributes) | |
let thirdString = NSAttributedString(string: "shit") | |
firstString.append(secondString) | |
firstString.append(thirdString) | |
//SwiftUI Attributed Strings | |
( | |
Text("Holy ") | |
.kerning(10) | |
.font(.system(size: 18)) | |
+ | |
Text("fucking ") | |
.foregroundColor(.red) | |
+ | |
Text("shit") | |
.font(.custom("Georgia", size: 16)) | |
.fontWeight(.bold) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment