Skip to content

Instantly share code, notes, and snippets.

@tx-TEM
Last active October 6, 2019 12:42
Show Gist options
  • Save tx-TEM/aaea4bb7178e4466c3d04ca643985834 to your computer and use it in GitHub Desktop.
Save tx-TEM/aaea4bb7178e4466c3d04ca643985834 to your computer and use it in GitHub Desktop.
SwiftUIメモ
import SwiftUI

struct ContentView: View {
    @State var count = 1

    var body: some View {
        VStack(alignment: .center) {
            Text("Count")
                .font(.title)
                .background(Color.white)

            Text("\(count)")
                .font(.system(size: 64))
                .background(Color.white)
                .padding(16)

            Spacer()

            Button(action: {
                self.count += 1
            }, label: {
                Text("Click")
                    .font(.system(size: 32))
                    .foregroundColor(Color.white)
                    .background(Color.gray)
                    .padding(16)
                    .frame(minWidth: 0, maxWidth: .infinity)
            })
            .background(Color.blue)
            .padding(16)
        }
        .background(Color.red)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
  • VStackのWidthは子のサイズに影響されていそう
  • Buttonのタップ領域はTextに指定した横幅
  • ButtonのWidthはTextに指定した横幅に影響されてそう
  • ButtonのWidthを設定するだけだとタップ領域は広がらない
  • paddingは他のViewとの距離 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment