Published Dec 9, 2022Updated Mar 2, 2023
Contribute to Docs

A ViewModifier is a protocol that can be called on a particular view. Modifier methods adhere to the protocol and return a new, altered View that will replace the originally created View.


struct MyView: View {
    var body: some View {
        View(s) here
            Modifier methods like .bold() can be called underneath a View.
            Multiple modifiers can be chained using dot notation.


The following example displays some text:

import SwiftUI
struct ContentView: View {
var name: String = "Sam"
var body: some View {
Text("Hello \(name)")

In the example above, the .font() and .bold() modifiers are called on a Text view. In addition, a built-in text style, .title property, is passed into the .font() modifier.

This will display:

SwiftUI Modifier


Applies an animation to a view.
Applies a background to a view, which can be customized depending on the provided parameters.
Moves text up or down relative to its baseline.
Applies a bold style to text characters in a View.
Applies a border to a view, which can be customized with a specified style and width.
Gives a view the ability to be dragged.
Applies a destination to drop a draggable view.
Applies a specified font to text in a view.
Sets the font weight of the text in Text view.
Sets the foreground color that is displayed in a view.
Applies an invisible frame around the view with the specified sizes.
Indicates that the font inside a view should have an italic style applied to it.
Adjusts the spacing size between text characters in a view.
Specifies the keyboard type to use for text entry.
Layers the specified views in front of another view.
Applies spacing around a view.
Configures an image in a View to resize itself to fit the surrounding space of its parent container.
Scales the view to fill its parent view while maintaining the original aspect ratio.
Scales the view to fit its parent view while maintaining the original aspect ratio.
Applies a horizontal line through the middle of the text in a string.
Applies a specified style to a text field.
Sets the tint color displayed in a view.
Adjusts the spacing of the characters in a Text view.
Applies an underline style to text characters in a view.

All contributors

Looking to contribute?

Learn SwiftUI on Codecademy