Contents

AttributeScopes.SwiftUIAttributes.BackgroundColorAttribute

A key for the color that fills the area behind a run of attributed text.

Declaration

@frozen enum BackgroundColorAttribute

Overview

Set this key to highlight part of a string, such as the way a search result marks the term someone typed:

var line = AttributedString("No matches for swift")
if let match = line.range(of: "swift") {
    line[match].backgroundColor = .yellow
}

Text(line)