Skip to main content

How to blend views together

About 1 minSwiftSwiftUIArticle(s)bloghackingwithswift.comcrashcourseswiftswiftuixcodeappstore

How to blend views together 관련

SwiftUI by Example

Back to Home

How to blend views together | SwiftUI by Example

How to blend views together

Updated for Xcode 15

When placing one view over another, you can control the way they overlap by using the blendMode() modifier. This contains a variety of ways you can mix colors together, such as using their difference or using a color burn – these will be familiar if you’ve used Core Graphics or something like Photoshop before.

To demonstrate this we could create a ZStack with two overlapping circles inside, where the second has a .multiply blend mode so that it darkens the colors behind it:

ZStack {
    Circle()
        .fill(.red)
        .frame(width: 200, height: 200)
        .offset(x: -50)
        .blendMode(.screen)

    Circle()
        .fill(.blue)
        .frame(width: 200, height: 200)
        .offset(x: 50)
        .blendMode(.screen)
}
.frame(width: 400)
Similar solutions…
How to combine text views together | SwiftUI by Example

How to combine text views together
How to group views together | SwiftUI by Example

How to group views together
How to group views together with ControlGroup | SwiftUI by Example

How to group views together with ControlGroup
Composing views to create a list row | SwiftUI by Example

Composing views to create a list row
How to use @EnvironmentObject to share data between views | SwiftUI by Example

How to use @EnvironmentObject to share data between views

이찬희 (MarkiiimarK)
Never Stop Learning.