2
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.

【SwiftUI】貞子が出てきそうなUIを作成する

Posted at

はじめに

貞子が出てきそうなUIをSwiftUIで作成してみます。

完成形

simulator_screenshot_398401BE-05A8-4C3C-843D-42AFFD202FB8.png

実装

import SwiftUI

struct ColorNoiseView: View {
    let size: CGSize
    
    var body: some View {
        let colors = (0..<Int(size.width * size.height)).map { _ in
            Color(red: .random(in: 0...1), green: .random(in: 0...1), blue: .random(in: 0...1))
        }
        GeometryReader { geometry in
            ZStack {
                ForEach(0..<Int(size.width * size.height), id: \.self) { index in
                    Rectangle()
                        .fill(colors[index])
                        .frame(width: 1, height: 1)
                        .position(CGPoint(x: CGFloat(index % Int(size.width)), y: CGFloat(index / Int(size.width))))
                }
            }
        }
        .frame(width: size.width, height: size.height)
    }
}

使い方

import SwiftUI

struct ContentView: View {
    var body: some View {
        ColorNoiseView(size: .init(width: 300, height: 300))
    }
}

おわり

作ってる途中に貞子出てきました

2
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
2
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?