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 |
Tags
- 리펙터링
- UICollectionView
- Xcode
- swiftUI
- ribs
- 클린 코드
- 리팩토링
- 애니메이션
- Clean Code
- combine
- rxswift
- HIG
- 스위프트
- UITextView
- Observable
- ios
- SWIFT
- uitableview
- map
- tableView
- MVVM
- Refactoring
- swift documentation
- uiscrollview
- Human interface guide
- RxCocoa
- clean architecture
- 리펙토링
- collectionview
- Protocol
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - SwiftUI] Stepper 사용 방법 본문
Stepper
struct Stepper<Label> where Label : View
- 아래 Stepper 생성자를 이용하여 구현
public init(
@ViewBuilder label: () -> Label,
onIncrement: (() -> Void)?,
onDecrement: (() -> Void)?,
onEditingChanged: @escaping (Bool) -> Void = { _ in }
)
- onIncrement와 onDecrement에서 쓸 @State 프로퍼티 준비
@State private var value = 0
let colors = [
Color.orange,
.red,
.gray,
.blue,
.green,
.purple,
.pink
]
- @ViewBuilder에는 Text를 넣어서 구현
var body: some View {
Stepper {
Text("Value: \(value), color: \(colors[value].description)")
} onIncrement: {
value += 1
guard value >= colors.count else { return }
value = 0
} onDecrement: {
value -= 1
guard value < 0 else { return }
value = colors.count - 1
}
}
- 직접 value값을 컨트롤하는 onIncrement, onDecrement가 아닌 다른 방법
public init<V>(
_ titleKey: LocalizedStringKey,
value: Binding<V>,
step: V.Stride = 1,
onEditingChanged: @escaping (Bool) -> Void = { _ in }
) where V : Strideable
- 몇씩 올라가는지 step 값과 range값을 사용
Stepper(
value: $value,
in: 0...50,
step: 5
) {
Text("Current: \(value)")
}
* 전체 코드: https://github.com/JK0369/ExStepper-SwiftUI
* 참고
https://developer.apple.com/documentation/swiftui/stepper?changes=_2_4
'iOS 기본 (SwiftUI)' 카테고리의 다른 글
[iOS - SwiftUI] HStack, VStack, ZStack, LazyStack 사용 방법 (+ @unknown, @frozen) (0) | 2022.08.24 |
---|---|
[iOS - SwiftUI] NavigationView, NavigationLink 사용 방법 (0) | 2022.08.23 |
[iOS - SwiftUI] Slider 사용 방법 (0) | 2022.08.21 |
[iOS - SwiftUI] DatePicker, ColorPicker 사용 방법 (0) | 2022.08.20 |
[iOS - swiftUI] Picker, PickerStyle 사용 방법 (2) | 2022.08.17 |
Comments