본문 바로가기

iOS/SwiftUI

[SwiftUI] "손쉬운 사용" 버튼 스타일

iOS 설정의 “손쉬운 사용 → 버튼 사용”을 설정했을 때,

SwiftUI 의 기본 버튼 스타일을 사용하면 회색 배경이 생기는 문제가 발생합니다.

 

"손쉬운 사용" 설정을 해도 기본 버튼 스타일이 그대로 있길 원한다면 아래처럼 커스텀 버튼 스타일을 지정해주어야 합니다.

struct BasicButtonStyle: ButtonStyle {
    func makeBody(configuration: Configuration) -> some View {
        configuration.label
            .opacity(configuartion.isPressed ? 0.3 : 1)
            .animation(configuartion.isPressed ? .none : .easeInOut(duration: 0.15), value: configuartion.isPressed)
    }
}

struct CustomView: View {
    var body: some View {
        Button {
            // tab event handle
        } label: {
            Text("버튼");
        }.buttonStyle(BasicButtonStyle())
    }
}