Swift/SwiftUI
-
[SwiftUI] zstack button not working, ZStack에서의 버튼 동작, zIndex()Swift/SwiftUI 2023. 11. 24. 23:02
오류 코드 ZStack{ // Stack 배열 } ZStack에 alignment를 안줬더니 버튼이 안눌린다. 수정한 코드 ZStack(alignment: .bottomTrailing){ ZStack에 alignment를 지정 ZStack(alignment: .bottomTrailing){ //1) 위에 올라오는 버튼 HStack{ Button { print("button pressed") if isStopedtimer == false{ isStopedtimer = true } else { isStopedtimer = false withAnimation { index = index < images.count ? index + 1 : 1 // selectedNum 값은 images 배열의 element 값..
-
[SwiftUI] scaledToFill vs scaledToFit와 frame의 순서Swift/SwiftUI 2023. 11. 19. 18:33
scaledToFill vs scaledToFit ⚠️ 순서에 유의! scaledToFill이 먼저 와야함 HStack{ KFImage(URL(string: feed.profileImage)) .resizable() .clipShape(Circle()) //순서에 유의! .frame(width: .screenWidth*0.13, height: .screenWidth*0.13) .scaledToFill() .border(.black) Text("\(feed.creatorID)") Spacer() } 먼저 이미지를 조정하고 사이즈를 잘라준다. HStack{ KFImage(URL(string: feed.profileImage)) .resizable() .clipShape(Circle()) //scaledToF..
-
[SwiftUI] list에서 가장자리 여백 제거, 구분선 제거Swift/SwiftUI 2023. 11. 19. 17:08
가장자리 여백을 제거해봅시다. 전 -> 후 import SwiftUI struct FeedListView: View { @ObservedObject var feedStore: FeedStore = FeedStore() var body: some View { NavigationView { List { ForEach(feedStore.feeds,id: \.self) { feed in FeedCellView(feedStore: feedStore, feed: feed) // list 여백 제거 .listRowInsets(EdgeInsets()) // listSeparator 제거 .listRowSeparator(.hidden) } } .listStyle(PlainListStyle()) } } } list 여백 ..
-
Zstack에서 버튼이 중첩해서 눌리는 현상(position vs offset)Swift/SwiftUI 2023. 10. 1. 17:31
에러 현상 : 버튼 이외의 화면을 눌렀는데 버튼이 눌리는 현상. 해결 방법 : Text가 아닌, Button 전체(label)에 position을 적용, position은 View가 사용할 수 있는 크기만큼 늘어난다. -> text영역 이외도 text로 적용된다. ZStack{ HStack{ Button { Coordinator.shared.clothingBinStore.handleButtonTap(buttonType: .currentMap) } label: { Text("현재 지도") .background( Rectangle() .fill(.white) ) .padding() // Text자체에 적용하는 것이 아님 (삭제) .position(x:350, y:80) } //이 버튼에 포지션 적용 .pos..
-
Property WrapperSwift/SwiftUI 2023. 9. 28. 21:12
SwiftUI에서 Property Wrappers는 특별한 기능을 갖는 속성을 정의하는 데 사용됩니다. Property Wrappers를 사용하면 코드를 간결하고 읽기 쉽게 만들 수 있습니다. @State: SwiftUI 뷰의 상태를 저장하는 데 사용되며, 값을 변경할 때마다 뷰가 다시 렌더링됩니다. 보통 UI 컴포넌트의 상태를 저장하는 데 사용됩니다. @Binding: 부모 뷰에서 자식 뷰로 값을 전달하고, 자식 뷰에서 부모 뷰로 값을 다시 전달하는 데 사용됩니다. 부모 뷰의 속성을 자식 뷰에서 변경하는 데 유용합니다. @ObservedObject: 외부에서 제공되는 ObservableObject 프로토콜을 준수하는 객체의 상태를 저장하는 데 사용됩니다. 뷰에서 @ObservedObject 속성을 참조..
-
differences between @Binding and @ObservedObjectSwift/SwiftUI 2023. 8. 24. 00:34
In this example, we'll create a simple app with a counter. Tapping a button in the child view will increment the counter, and the updated counter value will be shown in both the parent and child views. import SwiftUI struct ContentView: View { @State private var counter: Int = 0 var body: some View { VStack { Text("Counter in Parent: \(counter)") ChildView(counter: $counter) } } } struct ChildVi..
-
sheet (Q)Swift/SwiftUI 2023. 8. 2. 01:12
Button("포켓몬 추가") { self.isPresented.toggle() }.sheet(isPresented: $isPresented) { //띄울 뷰 & 뷰에 전달할 바인딩 값 AddPocketmonView(pocketmonStore: pocketmonStore, isShowingAddSheet: $isShowingAddSheet) } sheet(isPresented:onDismiss:content:) Presents a sheet / when a binding to a Boolean value that you provide is true. ⚠️ 오류: 바인딩 값 변수를 같게 (isPresented)로 통일한다. 예제 코드 struct ContentView: View { @State privat..