티스토리 뷰

macOS, iOS

[SwiftUI] ButtonStyle

SweetDev 2021. 2. 23. 21:09

 

UIKit에서는 UIButton을 상속받은 클래스를 만들었듯...

SwiftUI에서는 ButtonStyle을 사용하게 된다!

 

 

struct HomeScrollButtonStyle: ButtonStyle {
  var isSelected = false
  func makeBody(configuration: Self.Configuration) -> some View {
    VStack {
      configuration.label
        .foregroundColor(isSelected ? Color.red : Color.black)
        .font(isSelected ? .largeTitle : .body)
      if isSelected {
        Circle().frame(width: 5, height: 5, alignment: .center)
      }
    }
  }
}

이런식으로 써주면 된다. 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함