티스토리 뷰
iOS SwiftUI
iOS SwiftUI Custom Segmented Control Fixed Width (커스텀 세그먼트 컨트롤, TabView TabMenu, TabBar) 크기 고정 버전
GonsLab 2025. 1. 1. 00:00728x90
반응형
import SwiftUI
/// 커스텀 세그먼트 뷰 (가로 꽉 채우는 고정 너비 버전)
struct SegmentedFixedView: View {
let segments: [String]
@Binding var currentPage: Int
@Namespace private var name
var body: some View {
HStack(spacing: 0) {
ForEach(segments.indices, id: \.self) { index in
Button {
currentPage = index
} label: {
VStack {
Text(segments[index])
.font(.footnote)
.fontWeight(.medium)
.foregroundStyle(currentPage == index ? .orange : Color(uiColor: .systemGray))
ZStack {
Capsule()
.fill(.clear)
.frame(height: 4)
if currentPage == index {
Capsule()
.fill(.orange)
.frame(height: 4)
.matchedGeometryEffect(id: "Tab", in: name)
}
}
}
}
}
}
.animation(.spring(duration: 0.3), value: currentPage)
}
}
#Preview {
struct Preview: View {
var segments: [Color] = [.red, .green, .blue]
@State var currentPage = 0
var body: some View {
VStack {
SegmentedFixedView(segments: segments.map { "\($0)" },
currentPage: $currentPage)
TabView(selection: $currentPage) {
ForEach(segments.indices, id: \.self) { index in
segments[index]
}
}
.tabViewStyle(.page(indexDisplayMode: .never))
.scrollTargetBehavior(.paging)
}
.ignoresSafeArea(.all, edges: .bottom)
}
}
return Preview()
}
https://medium.com/@c64midi/android-style-segmented-control-in-swiftui-f2d9e8469bdf
iOS
Swift
Xcode
Objective-C
SwiftUI
UISegmentedControl
Picker
탭뷰
탭뷰
탭메뉴
728x90
반응형
'iOS SwiftUI' 카테고리의 다른 글
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- custom segment
- picker
- SKPayment
- 엑스코드
- permission
- Authorization
- SKProductsRequestDelegate
- Localizations
- SKPaymentTransactionObserver
- 로컬라이징
- Xcode
- TabView
- 스위프트
- indicator
- 테이블뷰
- localizing
- Reject
- ios
- 심사
- presentationcompactadaptation
- Language
- AppStore
- TabBar
- 다국어
- swiftUI
- 아이오에스
- 인디케이터
- 리젝
- SWIFT
- 프로그레스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함