Swiftui tips: text background full screen background

Time:2021-2-22

In the process of using swiftui, we often encounter the problem of setting the background, especially we need to set the global background. What should we do at this time.

The value and harvest of this paper

After reading this article, you will be able to make the following interface

Swiftui tips: text background full screen background

Swiftui tips: text background full screen background

After reading this article, you will master the skills

Swiftui is wrapped layer by layer. We can wrap any view with a zstack

        ZStack {
            Color.clear
            self
        }
    }
  • Build your own decorator
extension View {
    func expandable () -> some View {
     //Your code
        }
    }
}

Project source code

import SwiftUI

extension View {
    func expandable () -> some View {
        ZStack {
            Color.clear
            self
        }
    }
}


struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
        .expandable()
        .background(Color.orange)
    }
}

Technical exchange

QQ:3365059189
Swiftui technology exchange QQ group: 518696470

  • Please pay attention to my column icloudend, swiftui tutorial and source code

https://www.jianshu.com/c/7b3…