Last active
May 21, 2024 00:14
-
-
Save benigumocom/3d471772fa10a8167663b07fb0d9851c to your computer and use it in GitHub Desktop.
【Swift】Color の RGB + Opacity の数値を求める 👉 https://android.benigumo.com/20240518/color-rgbo/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct TestColorValues: View { | |
var color: Color | |
@Environment(\.self) private var environment | |
private var resolved: Color.Resolved { | |
color.resolve(in: environment) | |
} | |
var body: some View { | |
VStack { | |
Text("\(resolved)") | |
Text(String(format: "R: %.3f", resolved.red)) | |
Text(String(format: "G: %.3f", resolved.green)) | |
Text(String(format: "B: %.3f", resolved.blue)) | |
Text(String(format: "O: %.3f", resolved.opacity)) | |
} | |
.monospaced() | |
.padding() | |
.background(color) | |
} | |
} | |
#Preview("TestColorValues") { | |
VStack { | |
TestColorValues(color: Color(.secondarySystemBackground)) | |
.environment(\.colorScheme, .light) | |
TestColorValues(color: Color(.secondarySystemBackground)) | |
.environment(\.colorScheme, .dark) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment