Skip to content

Instantly share code, notes, and snippets.

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

takehito Koshimizu-Takehito

🏝️
View GitHub Profile
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created November 15, 2024 04:04
長方形アニメーション
import SwiftUI
struct ContentView: View {
@StateObject private var viewModel = RectsViewModel()
var body: some View {
GeometryReader { geometry in
TimelineView(.animation) { timeline in
Canvas {context, size in
let rects = viewModel.rects
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Last active November 4, 2024 08:46
Date.FormatStyle の出力サンプル
import SwiftUI
struct ContentView: View {
@State private var date = ISO8601DateFormatter().date(from: "2025-01-01T00:00:00+09:00")!
@State private var code: LanguageCode = .japanese
@State private var timeZoneID: TimeZoneID = .jst
@State private var calendarName: CalendarName = .gregorian
var body: some View {
NavigationStack {
import SwiftUI
import UIKit
extension UIDatePicker.Mode {
static var fallbackYearAndMonth: Self {
if #available(iOS 17.4, *) {
.yearAndMonth
} else {
.init(rawValue: 4269) ?? .date
}
@Koshimizu-Takehito
Koshimizu-Takehito / DynamicTypeSize.swift
Created October 20, 2024 10:19
ダイナミックタイプを利用した場合の標準フォントのスケール
import SwiftUI
#Preview {
@Previewable @State var value: Double = 3.0
VStack {
SampleView()
.environment(\.dynamicTypeSize, .allCases[Int(value)])
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
.contentTransition(.numericText())
Text("\(DynamicTypeSize.allCases[Int(value)])")
@Koshimizu-Takehito
Koshimizu-Takehito / MyFontSize.swift
Last active October 20, 2024 09:02
ScaledMetric と DynamicTypeSizeでフォントサイズを変更するサンプル
import SwiftUI
struct ContentView: View {
@State var value: Double = 4.0
let text = Text("Hello")
var body: some View {
VStack {
Grid(alignment: .leading) {
GridRow {
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created October 14, 2024 07:52
外観モードの変更にアニメーションをつける
import SwiftUI
struct ContentView: View {
@State var isDark = false
@State var currenct = ColorScheme.light
@Environment(\.colorScheme) var environment
var body: some View {
NavigationStack {
Form {
@Koshimizu-Takehito
Koshimizu-Takehito / SampleViewController.swift
Last active October 11, 2024 14:54
UIViewControllerRepresentableのレイアウト処理のサンプル
import UIKit
import SwiftUI
class SampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let traits = [UITraitPreferredContentSizeCategory.self]
registerForTraitChanges(traits) { (self: Self, _) in
self.view.invalidateIntrinsicContentSize()
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()