macOS, iOS

[SwiftUI] 버튼에 corner radius있는 테두리 추가해주기

SweetDev 2021. 2. 27. 11:41

 

선택 했을때,  안했을 때!

 

cornerRadius랑 background때문에 약간 고생했다 ㅠ

struct GenderStyle: ButtonStyle {
  @State var isSeleceted: Bool
  func makeBody(configuration: Configuration) -> some View {
    configuration.label
      .padding(.vertical, 12)
      .padding(.horizontal, 45)
      .foregroundColor(isSeleceted ? Color.white : Color("coolGrey"))
      .background(isSeleceted ? Color("lightPeriwinkle") : Color.white)
      .cornerRadius(8)
      .overlay(RoundedRectangle(cornerRadius: 8)
        .stroke(Color("silver"), lineWidth: 2)
      )
  }
}

팁은..padding을 Label에다가 추가하는 것, cornerRadius를 overlay 에다가도 주고, label에다가도 주는 것이었다.