반응형
Notice
Recent Posts
Recent Comments
Link
- Today
- Total
04-11 16:56
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- SQL
- SWIFT
- 딥러닝
- r
- MVC
- 시각화
- rxswift
- barplot
- struct
- scheduledTimer
- ios
- Observable
- HTTP
- Request
- sigmoid
- cocoapods
- ReLU
- 연산자
- substr
- 오블완
- Optional
- swiftUI
- tapply
- 티스토리챌린지
- Linux
- rest api
- 명령어
- Python
- deeplearning
- decode
Archives
iOS 개발 기록 블로그
SwiftUI Button의 Background가 클릭되지 않는 경우 본문
반응형
예를 들어 위와 같은 화면에 버튼이 있다고 생각해보자.
기본적으로 "선택하기" 부분만 클릭이 되고
나머지 백그라운드 부분이 클릭되지 않는다.
이 경우에 아래와 같이 하면 백그라운드 영역도 클릭이 가능하게 된다.
struct ChooseButtonView: View {
var body: some View {
Button(action: {
print("Tapped the Button!")
}, label: {
Text("선택하기")
.frame(maxWidth: .infinity)
.padding()
.background(Color.accentColor)
.foregroundColor(.white)
.cornerRadius(12)
.padding(.horizontal, 20)
})
}
}
Button을 타이핑하면 내장되어 있는 코드 스니펫?이 나오는데
이중에 위 이미지처럼 action:label: 이거로 하면 된다.
Label 자체를 키워버린 것이다.
왜인지는 모르겠지만 SwiftUI에서는 Label의 영역만 Tap이 가능하게 만들어 놓은 것 같다.
아래처럼 해도 똑같이 된다.
Button {
print("Tapped the Button!")
} label: {
Text("선택하기")
.frame(maxWidth: .infinity)
.padding()
.background(Color.accentColor)
.foregroundColor(.white)
.cornerRadius(12)
.padding(.horizontal, 20)
}
반응형
'iOS > SwiftUI' 카테고리의 다른 글
[SwiftUI] @ToolbarContentBuilder로 가독성 개선 (0) | 2024.03.14 |
---|---|
[SwiftUI] 네비게이션바 알 수 없는 여백 없애버리기 (0) | 2024.03.13 |
[SwiftUI] .navigationBarBackButtonHidden() 처리 후 PopSwipeGesture 버그 수정하기 (0) | 2024.03.12 |
[SwiftUI] @Environment(\.presentationMode) 사용해서 간편하게 View dismiss 하기 (0) | 2024.03.11 |