Skip to content

Instantly share code, notes, and snippets.

View Koshimizu-Takehito's full-sized avatar
🏝️

takehito Koshimizu-Takehito

🏝️
View GitHub Profile
import SwiftUI
// Xcode: 16.0
// Swift: 6.0
struct EnumPicker<Enum>: View where Enum: CaseIterable & Hashable, Enum == Enum.AllCases.Element, Enum.AllCases: RandomAccessCollection {
@Binding var selection: Enum
var body: some View {
Picker(String(describing: Enum.self), selection: $selection) {
ForEach(Enum.allCases, id: \.self) { value in
@Koshimizu-Takehito
Koshimizu-Takehito / RingSlider.swift
Last active September 9, 2024 05:17
RingSlider
import SwiftUI
struct ContentView: View {
@State var ratio: Double = 0
var body: some View {
ZStack {
Color(hue: 1, saturation: 0.3, brightness: 1)
.hueRotation(.degrees(360 * ratio))
.ignoresSafeArea()
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Last active August 4, 2024 03:14
UnevenRoundedRectangle Sample 2
import SwiftUI
struct ContentView: View {
@ViewBuilder
private func leftHandSide() -> some View {
HelloWorld()
.clipShape(Rectangle())
HelloWorld()
.clipShape(RoundedRectangle(cornerRadius: 20))
HelloWorld()
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created August 4, 2024 01:26
UnevenRoundedRectangle Sample
import SwiftUI
struct ContentView: View {
var body: some View {
Group {
HelloWorld()
.clipShape(UnevenRoundedRectangle(
topLeadingRadius: 80,
bottomTrailingRadius: 80
))
import SwiftUI
extension Color {
static var random: Self {
Color(
hue: .random(in: 0..<1),
saturation: .random(in: (0.9)..<1),
brightness: .random(in: (0.9)..<1)
)
}
import SwiftUI
struct ContentView: View {
@Environment(\.colorScheme) var scheme
private let date = Date()
private let colors = [Color.green, .pink, .blue, .orange, .purple]
private let titles = ["NEON", "GLOW", "LIGHT", "SHINE", "BRIGHT"]
var body: some View {
TimelineView(.animation) { context in
import SwiftUI
struct ContentView: View {
@State var progress = 0.0
var body: some View {
ZStack {
Ring(value: progress, speed: 4)
.foregroundStyle(gradation(.yellow, .orange))
.frame(width: 120)
import SwiftUI
struct ContentView: View {
@State var progress = 0.0
var body: some View {
ProgressRing(value: progress)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.contentShape(.rect)
.ignoresSafeArea()
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created July 28, 2024 06:04
Buttonがセルになるサンプル
import SwiftUI
struct ContentView: View {
@State private var show = false
@State private var items: [Item] = .samples()
var body: some View {
ScrollView {
LazyVStack {
ForEach(items.indices, id: \.self) { index in
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Last active July 28, 2024 03:12
ScrollView + LazyVStack アニメーション
import SwiftUI
struct ContentView: View {
@State private var item: [Item] = .samples()
@State private var show = false
var body: some View {
ScrollView {
LazyVStack {
ForEach(item.indices, id: \.self) { index in