.strikethrough()
Published Feb 20, 2023
Contribute to Docs
The .strikethrough
view modifier method in SwiftUI can be used to strike through text within a view.
Note: This method is specifically for use with text, so it can be applied as a view modifier to any view that displays text, such as a Text or Label View. However, it cannot be applied to views that do not display text, such as an Image View.
Syntax
Text("Some Text")
.strikethrough(parameters)
This method has two optional parameters:
active
: A boolean value that determines whether the strikethrough should be applied or not. This parameter defaults to true.color
: A color value used to color the strikethrough. This parameter defaults to the color of the text.
Example
The following example demonstrates how to use the .strikethrough()
method to apply a blue strikethrough to text:
var body: some View {Text("Here is a TextView with the .strikethrough() method applied to it using custom parameters.").strikethrough(true, color: .blue)}
This will display:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SwiftUI on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours