Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 스위프트
- Observable
- combine
- map
- uitableview
- rxswift
- UITextView
- Refactoring
- scrollview
- RxCocoa
- UICollectionView
- ios
- uiscrollview
- tableView
- Xcode
- SWIFT
- collectionview
- swiftUI
- 클린 코드
- 리펙토링
- 애니메이션
- HIG
- Clean Code
- ribs
- MVVM
- clean architecture
- swift documentation
- Human interface guide
- 리팩토링
- Protocol
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - SwiftUI] 튜토리얼 - 11. toolbar, ToolbarItemGroup, sheet 사용 방법 본문
iOS 튜토리얼 (SwiftUI)
[iOS - SwiftUI] 튜토리얼 - 11. toolbar, ToolbarItemGroup, sheet 사용 방법
jake-kim 2022. 7. 13. 01:28

toolbar

- TabBar와의 차이점
- TabBar: 현재 컨텍스트와 연관되지 않은 화면이동
- ToolBar: 현재 컨텍스트와 관련된 항목 추가, 삭제, 주석 추가, 사진 촬영과 같은 일
* toolbar의 Human Interface guide 관련 구체적인 내용은 이전 포스팅 글 참고
- toolbar를 사용하기 위해 네비게이션 뷰로 이루어진 뷰 준비
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Toolbar 예제")
.padding()
}
.navigationTitle("타이틀")
}
}
}
- toolbar를 추가할땐 navigationTitle을 추가하듯이 바로 밑에다 .toolbar로 선언
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Toolbar 예제")
.padding()
}
.navigationTitle("타이틀")
.toolbar { // <-
Button {
print("tap!")
} label: {
Label("Profile", systemImage: "person.crop.circle")
}
}
}
}
}

ToolbarItemGroup
- .toolbar 클로저 안에 ToolbarItemGroup(placement:) 사용이 가능
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Toolbar 예제")
.padding()
}
.navigationTitle("타이틀")
.toolbar {
ToolbarItemGroup(placement: .bottomBar) { // <-
Button("First") {
print("tap first button")
}
Button("Second") {
print("tap second button")
}
}
}
}
}
}

- 만약, ToolbarItemGroup(placement: .keyboard)로 하면 키보드가 올라올때 자동으로 그 위에 붙어있는 툴바로 변경

struct ContentView: View {
@State var name: String = ""
var body: some View {
NavigationView {
VStack {
TextField("input some text", text: $name)
.padding()
.background(Color(uiColor: .secondarySystemBackground))
Text("Toolbar 예제")
.padding()
}
.navigationTitle("타이틀")
.toolbar {
ToolbarItemGroup(placement: .keyboard) { // <-
Button("First") {
print("tap first button")
}
Button("Second") {
print("tap second button")
}
}
}
}
}
}
* 참고
https://developer.apple.com/tutorials/swiftui/working-with-ui-controls
'iOS 튜토리얼 (SwiftUI)' 카테고리의 다른 글
Comments
jake-kim님의
글이 좋았다면 응원을 보내주세요!