Jinsujin / SwiftUI

SwiftUIλ₯Ό 곡뢀해보고 ν™œμš©ν•˜λŠ” 곡간
0 stars 0 forks source link

Button #1

Closed Jinsujin closed 1 year ago

Jinsujin commented 1 year ago

πŸ‘‰ Document

Button을 μƒμ„±ν•˜λŠ” λ‹€μ–‘ν•œ 방법듀

  1. (default)λ¬Έμžμ—΄μ„ μž…λ ₯ν•˜μ—¬ Label 을 μƒμ„±ν•˜λŠ” λ²„νŠΌ

    Button("λ²„νŠΌμ˜ 타이틀") {
      // λ²„νŠΌμ„ λˆŒλ €μ„λ•Œ λ™μž‘ν•  Action μ •μ˜
    }
  2. Custom Label 을 ν‘œμ‹œν•˜λŠ” λ²„νŠΌ 생성

    Button {
      // λ²„νŠΌμ„ λˆŒλ €μ„λ•Œ λ™μž‘ν•  Action μ •μ˜
    } label: {
      // λ²„νŠΌμ˜ μƒκΉ€μƒˆ μ •μ˜
    }
  3. Custom Label 을 ν‘œμ‹œν•˜λŠ” role을 가진 λ²„νŠΌ 생성

    Button("Delete", role: .desctructive) {
      // λ²„νŠΌμ„ λˆŒλ €μ„λ•Œ λ™μž‘ν•  Action μ •μ˜
    }

예제

  1. λΌμš΄λ“œ 처리된 λ²„νŠΌ λ§Œλ“€κΈ°

    Button {
      print("Hello world!")
    } label: {
      Text("Touch Me")
          .frame(width: 200, height: 40, alignment: .center)
          .foregroundColor(.white)
          .background(.purple)
          .cornerRadius(20)
    }
  2. 이미지 λ²„νŠΌ

    Button {
      print("hello")
    } label: {
      Image(systemName: "folder")
          .resizable() // 이미지 μ‚¬μ΄μ¦ˆλ₯Ό ν”„λ ˆμž„ 크기에 λ§žμΆ˜λ‹€.
          .frame(width: 80, height: 60, alignment: .center)
    }
  3. ν…μŠ€νŠΈμ™€ 이미지λ₯Ό ν•¨κ»˜ μ‚¬μš©ν•˜κΈ°

    Button {
      print("hello")
    } label: {
      HStack {
          Image(systemName: "folder")
              .resizable()
              .frame(width: 80, height: 60, alignment: .center)
          Text("Save File")
              .foregroundColor(.brown)
      }
    }