A sample project showing how to implement custom Swift function builder using NSAttributedString
as an example.
Usage:
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label.attributedText = NSAttributedString {
NSAttributedString {
"Folder "
UIImage(systemName: "folder")!
}
"\n"
NSAttributedString {
"Document "
UIImage(systemName: "doc")!.withRenderingMode(.alwaysTemplate)
}
.withAttributes([
.font: UIFont.systemFont(ofSize: 32),
.foregroundColor: UIColor.red
])
}
}
}
Result: