万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    時間ピッカー SwiftUI watchOS

    こんな感じで作って

    struct TimePicker: View {
        @State private var selectedHour = 0
        @State private var selectedMin = 0
        @State private var selectedSecond = 0
    
        let height: CGFloat = 100.0
        
        var body: some View {
            HStack {
                VStack {
                    Picker(selection: self.$selectedHour, label: Text("Hour")) {
                        ForEach(0..<24) { hour in
                            Text(String(format: "%02d", hour))
                        }
                    }
                }
                .frame(height: height)
                .clipped()
                .border(Color.blue)
    
                VStack {
                    Picker(selection: self.$selectedMin, label: Text("Min")) {
                        ForEach(0..<60) { min in
                            Text(String(format: "%02d", min))
                        }
                    }
                }
                .frame(height: height)
                .clipped()
                .border(Color.blue)
    
                VStack {
                    Picker(selection: self.$selectedSecond, label: Text("Sec")) {
                        ForEach(0..<60) { sec in
                            Text(String(format: "%02d", sec))
                        }
                    }
                }
                .frame(height: height)
                .clipped()
                .border(Color.blue)
            }
        }
    }

    TimePicker()を使う。 2桁の数字。

    f:id:shinriyo:20210101084141p:plain

    Text(":")

    みたいに間に挟むのもあり。

    プルダウン SwiftUI AppleWatch watchOS

    https://stackoverflow.com/questions/57091718/how-to-display-a-picker-in-swiftui-completely-in-a-scrollview-or-vstack-with-oth これみた

    以下を定義して

        @State private var exercises = ["Unterarmstütz", "Dehnen", "Kopfstand", "Handstand"]
        @State private var selectedExercise = "Plank"

    これやる

                    // use GeometryReader for height & weight
                    GeometryReader { geometry in
                        ScrollView() {
                            ForEach(self.exercises, id: \.self) { exercise in
                            Button(action: {
                            self.selectedExercise = String(exercise)
                                }) {
                                    Text(exercise)
                                }
                            }
                        }
                    }.frame(
                        height: 50, alignment: .center
                    )

    色もつく

                    // use GeometryReader for height & weight
                    GeometryReader { geometry in
                        ScrollView() {
                            ForEach(self.exercises, id: \.self) { exercise in
                                Button(action: {
                                    self.selectedExercise = exercise
                                        }) {
                                            Text(exercise)
                                        }.foregroundColor(self.selectedExercise == exercise ? .green : .white)
                            }
                        }
                    }.frame(
                        height: 50, alignment: .center
                    )

    Apple Watch(watchOS)のためにCarthage入れ

    https://github.com/calda/WatchKitTimePicker これ使いたいけど、CocoaPodではなくてCarthageカルタゴ

    brew install carthage
    carthage bootstrap --platform watchOS

    してから

    carthage update --platform watchOS