ラベル iPhone の投稿を表示しています。 すべての投稿を表示
ラベル iPhone の投稿を表示しています。 すべての投稿を表示

2024年4月17日水曜日

iPhoneアプリ開発:画像の装飾

////  ContentView.swift//  Dice////  Created by jeff on 2024/04/09.//import SwiftUIstruct ContentView: View {    var body: some View {        VStack {            Image(systemName: "die.face.1")            Button {                print("ボタンが押されたよ")            } label:{                Text("サイコロを振る")            }        }        .padding()    }}#Preview {    ContentView()}
画像の装飾のために、モディファイアをつけると画像が直感的に変化していきます。
                .resizable()
                .scaledToFit()
              .frame(width:UIScreen.main.bounds.width/2)
                .padding()

Xcodeに登録されている画像の一覧を表示するためには、「Command+Shift+L」のショットカットキーを押せば以下のように表示されます。検索も可能で、スクロールして確認も可能です。

2024年4月8日月曜日

[Xcode]シミュレーターのソフトキーボードが表示されない「解決策」

Xcode Version:15.3, Simulator Version: 15.3

////  ContentView.swift//  TaxCalculator////  Created by jeff on 2024/04/07.//import SwiftUIstruct ContentView: View {    @State var inputText = ""    @State var Tax8 = 0.0    @State var Tax10 = 0.0    var body: some View {        VStack (spacing:20){            TextField("ここに文字を入力", text: $inputText)                .keyboardType(.numberPad)            Button("計算"){                Tax8 = (Double(inputText) ?? 0) * 0.08                Tax10 = (Double(inputText) ?? 0) * 0.10            }            Text("価格:\(inputText)")            Text("消費税8%:\(Tax8) "  )            Text("消費税10%:\(Tax10)")        }        .padding()    }}#Preview {    ContentView()}

上記Swiftコードの下線部に数字しか入力できないように、iPhoneのソフトキーボードを定義しているにもかかわらず、Xcodeでシミュレーションしたところ、下記のように、Macbook Airのキーボードで数字以外の入力ができます。しかも、ソフトキーボードが表示されません。

Simulator → I/O → Keyboard → Connect Hardware Keyboardが選択されていることは原因です。これを使用していると、パソコンのキーボードと連携しているため、ソフトキーボードが表示されません。

このチェックを外したところ、無事にソフトキーボードが表示され、数字しか入力できないように制限されています。

2024年4月6日土曜日

iPhoneアプリ開発講座(問題③)

////  ContentView.swift//  HelloSwiftUI////  Created by jeff on 2024/04/06.//import SwiftUIstruct ContentView: View {    @State var str = "Hello, SwiftUI"    var body: some View {        VStack {            ZStack{                Rectangle()                    .foregroundColor(.yellow)                    .frame(width:300, height: 300)                VStack{                    HStack{                        Rectangle()                            .foregroundColor(.black)                            .frame(width:60, height: 20)                        ZStack{                            Rectangle()                                .foregroundColor(.gray)                                .frame(width:90, height: 90)                            Rectangle()                                .foregroundColor(.white)                                .frame(width:70, height: 70)                            Rectangle()                                .foregroundColor(.black)                                .frame(width:20, height: 20)                        }                        ZStack{                            Rectangle()                                .foregroundColor(.gray)                                .frame(width:90, height: 90)                            Rectangle()                                .foregroundColor(.white)                                .frame(width:70, height: 70)                            Rectangle()                                .foregroundColor(.black)                                .frame(width:20, height: 20)                        }                        Rectangle()                            .foregroundColor(.black)                            .frame(width:60, height: 20)                    }                    ZStack{                        Rectangle()                            .foregroundColor(.black)                            .frame(width:70, height: 40)                        VStack{                            Rectangle()                                .foregroundColor(.white)                                .frame(width:60, height: 10)                            Rectangle()                                .foregroundColor(.red)                                .frame(width:60, height: 10)                        }                    }                }            }            Rectangle()                .foregroundColor(.blue)                .frame(width:300, height: 100)            HStack{                Rectangle()                    .foregroundColor(.black)                    .frame(width:70, height: 30)                Rectangle()                    .foregroundColor(.black)                    .frame(width:70, height: 30)            }        }    }}#Preview {    ContentView()}

iPhoneアプリ開発講座 by Rikuto Sato

iPhoneアプリ開発勉強SwiftUI (問題①、問題②)

////  ContentView.swift//  HelloSwiftUI////  Created by jeff on 2024/04/06.//import SwiftUIstruct ContentView: View {    @State var str = "Hello, SwiftUI"    var body: some View {        VStack {            Rectangle()                .foregroundColor(.orange)                .frame(width:200, height: 50)            Rectangle()                .foregroundColor(.red)                .frame(width:180, height: 20)            Rectangle()                .foregroundColor(.yellow)                .frame(width:180, height: 20)            Rectangle()                .foregroundColor(.brown)                .frame(width:180, height: 20)            Rectangle()                .foregroundColor(.green)                .frame(width:180, height: 20)            Rectangle()                .foregroundColor(.orange)                .frame(width:200, height: 50)        }        ZStack {            Rectangle()                .foregroundColor(.green)                .frame(width:300, height: 300)            VStack {                HStack{                    Rectangle()                        .foregroundColor(.black)                        .frame(width:70, height: 70)                    Rectangle()                        .foregroundColor(.black)                        .frame(width:70, height: 70)                }                Rectangle()                    .foregroundColor(.black)                    .frame(width:50, height: 20)                Rectangle()                    .foregroundColor(.black)                    .frame(width:100, height: 80)            }        }        .padding()    }}#Preview {    ContentView()}

SwiftUIアプリ開発講座 by RikutoSato