5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

お題は不問!Qiita Engineer Festa 2023で記事投稿!

【SwiftUI】インスタのかっこいい背景色を再現する

Posted at

はじめに

インスタにかっこいい背景があったのでSwiftUIで再現してみます

IMG_3400.PNG

実装

import SwiftUI

struct GradationBackgroundView<T: View>: View {
    @ViewBuilder var content: () -> T

    var body: some View {
        ZStack {
            LinearGradient(gradient: Gradient(colors: [.orange, .purple, .cyan, .blue, .green, .yellow]), startPoint: .topLeading, endPoint: .bottomTrailing)
                .edgesIgnoringSafeArea(.all)
            Rectangle()
                .foregroundStyle(Material.ultraThickMaterial)
                .edgesIgnoringSafeArea(.all)
            
            content()
        }
    }
}

使い方

import SwiftUI

struct ContentView: View {
    var body: some View {
        GradationBackgroundView {
            ScrollView {
                VStack {
                    ForEach(0..<100) { _ in
                        Text("テスト")
                    }
                }
            }
        }
    }
}

完成

simulator_screenshot_8561EA9E-2C22-4A48-A795-7D273F452E22.png

おわり

結構再現度高いと思います!

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?