본문 바로가기

2022/10

(23)
17. Toggle & Slider & ProgressView Toggle Apple Developer Documentation developer.apple.com struct ControlsView: View { @State private var toggleStat = true var body: some View { Image(systemName: toggleStat ? "lightbulb.fill" : "lightbulb") Toggle(isOn: $toggleStat) { Text("Switch it!") } } } title과 label로 이름을 설정하고, isOn에 State Variable을 전달해 해당 변수를 true 나 false로 반전시킨다. 기본 스타일은 너비 전체를 채우고, Control이 오른쪽, 높이는 콘텐츠 표시를 위한 최소한으로 지정된다...
16. Button & Link & Menu Button Apple Developer Documentation developer.apple.com 일반적으로 사용하는 파라미터는 아래와 같다 action Button의 동작 label Button의 UI title Button의 이름 role Alert, Context에 Button을 사용하는 경우 특정 역할을 부여 struct ControlsView: View { @State private var text = "" var body: some View { Text(text) Button("test", role: .destructive) { text = "Hello" } } } Link Apple Developer Documentation developer.apple.com struct Controls..
TextField 입력값 제한하기 입력값을 제한할 때는 보통 세 가지를 고려해야 한다. 숫자만 입력한다고 가정 해 보자. 사용자는 숫자키보드(numeric)가 아닌 SW키보드를 사용할 가능성이 있다. 블루투스나 iPad의 스마트 키보드등의 외장 HW키보드를 사용할 가능성이 있다. 복사, 붙여넣기로 값을 입력할 수 있다. struct LabelView: View { @State private var value = "" @State private var input = "" let formatter: NumberFormatter = { let formatter = NumberFormatter() formatter.numberStyle = .decimal return formatter }() var body: some View { Form { ..