diff --git a/demo.xcodeproj/project.pbxproj b/demo.xcodeproj/project.pbxproj index 765919c..144e7d1 100644 --- a/demo.xcodeproj/project.pbxproj +++ b/demo.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 96E93E9D2B622D00004AB649 /* NavigationPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E93E9C2B622D00004AB649 /* NavigationPageView.swift */; }; 96E93E9F2B62305F004AB649 /* UserNicknameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E93E9E2B62305F004AB649 /* UserNicknameView.swift */; }; 96E93EA12B623D4E004AB649 /* MessageDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E93EA02B623D4E004AB649 /* MessageDetailView.swift */; }; + 96E93EA32B63B164004AB649 /* RadioButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E93EA22B63B164004AB649 /* RadioButton.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -83,6 +84,7 @@ 96E93E9C2B622D00004AB649 /* NavigationPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationPageView.swift; sourceTree = ""; }; 96E93E9E2B62305F004AB649 /* UserNicknameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNicknameView.swift; sourceTree = ""; }; 96E93EA02B623D4E004AB649 /* MessageDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDetailView.swift; sourceTree = ""; }; + 96E93EA22B63B164004AB649 /* RadioButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButton.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -171,6 +173,7 @@ 968A6FB12B5FC3A2008609EE /* ShowMore.swift */, 968A6FB32B610C67008609EE /* KillCountDown.swift */, 968A6FB52B6113BE008609EE /* UserAccountCard.swift */, + 96E93EA22B63B164004AB649 /* RadioButton.swift */, ); path = Components; sourceTree = ""; @@ -359,6 +362,7 @@ 968A6F7F2B5F4E91008609EE /* HomeView.swift in Sources */, 968A6FA22B5F68AA008609EE /* ForgotView.swift in Sources */, 968A6F792B5F4E28008609EE /* TabBarView.swift in Sources */, + 96E93EA32B63B164004AB649 /* RadioButton.swift in Sources */, 96E93E9F2B62305F004AB649 /* UserNicknameView.swift in Sources */, 968A6FA82B5F6AF3008609EE /* CartView.swift in Sources */, 968A6FAA2B5F6B07008609EE /* CategoryView.swift in Sources */, diff --git a/demo.xcodeproj/project.xcworkspace/xcuserdata/jason.xcuserdatad/UserInterfaceState.xcuserstate b/demo.xcodeproj/project.xcworkspace/xcuserdata/jason.xcuserdatad/UserInterfaceState.xcuserstate index 738442b..01597d7 100644 Binary files a/demo.xcodeproj/project.xcworkspace/xcuserdata/jason.xcuserdatad/UserInterfaceState.xcuserstate and b/demo.xcodeproj/project.xcworkspace/xcuserdata/jason.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/demo/Components/RadioButton.swift b/demo/Components/RadioButton.swift new file mode 100644 index 0000000..9991038 --- /dev/null +++ b/demo/Components/RadioButton.swift @@ -0,0 +1,29 @@ +// +// RadioButton.swift +// demo +// +// Created by Jason on 2024/1/26. +// + +import SwiftUI + +struct RadioButton: View { + @Binding public var checked: Bool + var label: String = "" + var labelSize: Double = 14 + var radioSize: Double = 18 + + var body: some View { + HStack(spacing: 4, content: { + Image(systemName: checked ? "checkmark.circle.fill" : "circle") + .resizable() + .frame(width: radioSize, height: radioSize) + .foregroundColor(checked ? Color.orange : Color.gray) + Text(label) + .font(.system(size: labelSize)) + }) + .onTapGesture { + checked.toggle() + } + } +} diff --git a/demo/Models/TabBar.swift b/demo/Models/TabBar.swift index 4e529ba..414015b 100644 --- a/demo/Models/TabBar.swift +++ b/demo/Models/TabBar.swift @@ -17,13 +17,13 @@ struct TabItem: Identifiable { var tabItems = [ TabItem(icon: "book", text: "图书馆", tab: .home), TabItem(icon: "bag", text: "生活馆", tab: .explore), - TabItem(icon: "cart", text: "购物车", tab: .message), + TabItem(icon: "cart", text: "购物车", tab: .cart), TabItem(icon: "person", text: "个人中心", tab: .account) ] enum Tab: String { case home case explore - case message + case cart case account } diff --git a/demo/Views/Home/HomeView.swift b/demo/Views/Home/HomeView.swift index 1d00012..3f63a3b 100644 --- a/demo/Views/Home/HomeView.swift +++ b/demo/Views/Home/HomeView.swift @@ -22,12 +22,10 @@ struct HomeView: View { PartyReading NewBooks Categories - Spacer() } } .frame(maxWidth: .infinity) .padding(.horizontal, 12) - .padding(.bottom, 48) .background(Color.gray.opacity(0.2)) } diff --git a/demo/Views/Layouts/TabBarView.swift b/demo/Views/Layouts/TabBarView.swift index 62739cf..3900b76 100644 --- a/demo/Views/Layouts/TabBarView.swift +++ b/demo/Views/Layouts/TabBarView.swift @@ -12,23 +12,19 @@ struct TabBarView: View { var body: some View { NavigationView { - ZStack(alignment: .leading) { + ZStack { Group { switch selectedTab { case .home: HomeView() case .explore: MallView() - case .message: - MessageView() + case .cart: + CartView() case .account: UserView() } } - // .offset(y: -64) - // .safeAreaInset(edge: .top) { - // Color.clear.frame(height: 32) - // } HStack { ForEach(tabItems) { item in @@ -49,14 +45,11 @@ struct TabBarView: View { .shadow(color: selectedTab == item.tab ? Color.orange : Color.blue, radius: 15) } } - .padding(.top, 12.0) - .padding(.bottom, 32) + .padding(.vertical, 12.0) .background(Color("TabBarColor")) .frame(maxHeight: .infinity, alignment: .bottom) .shadow(color: Color.gray.opacity(0.5), radius: 6, x: 0, y: 6) - .ignoresSafeArea() } - .statusBarHidden(false) } .navigationViewStyle(.columns) } diff --git a/demo/Views/Mall/CartView.swift b/demo/Views/Mall/CartView.swift index 2c22ea8..0eb1cd1 100644 --- a/demo/Views/Mall/CartView.swift +++ b/demo/Views/Mall/CartView.swift @@ -8,8 +8,67 @@ import SwiftUI struct CartView: View { + @State private var isCheckAll = false + @State private var canSettle: Bool = false + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + VStack(spacing: 0) { + HStack(spacing: 2) { + Text("购物车") + .font(.system(size: 18)) + Text("(12)") + .font(.system(size: 12)) + .foregroundColor(Color.gray) + Spacer() + Text("管理") + .font(.system(size: 16)) + .foregroundColor(Color.black) + .onTapGesture { + canSettle.toggle() + } + } + .padding(.horizontal, 16) + .padding(.bottom, 12) + ScrollView(.vertical, showsIndicators: false) { + VStack(spacing: 12) { + ForEach(0 ..< 22) { _ in + Rectangle() + .fill(Color.white) + .frame(maxWidth: .infinity) + .frame(height: 100) + } + } + .padding(.bottom, 12) + } + .frame(maxWidth: .infinity) + .padding(.horizontal, 12) + + HStack(alignment: .center, spacing: 4) { + RadioButton(checked: $isCheckAll, label: "全选") + Spacer() + Text("合计") + .font(.system(size: 14)) + CamelPrice(amount: 0) + Text("结 算") + .font(.system(size: 14)) + .padding(.horizontal, 24) + .padding(.vertical, 12) + .foregroundColor(Color.white) + .background( + LinearGradient(colors: [ + canSettle ? Color.orange : Color.gray.opacity(0.5), + canSettle ? Color.red : Color.gray, + ], startPoint: .leading, endPoint: .trailing) + ) + .cornerRadius(32) + .onTapGesture {} + } + .padding(12) + .background(Color.white) + } + .animation(.linear(duration: 10), value: isCheckAll) + .padding(.bottom, 62) + .background(Color.gray.opacity(0.2)) } } diff --git a/demo/Views/Mall/MallView.swift b/demo/Views/Mall/MallView.swift index e024e74..951e5b9 100644 --- a/demo/Views/Mall/MallView.swift +++ b/demo/Views/Mall/MallView.swift @@ -9,7 +9,9 @@ import SwiftUI struct MallView: View { var body: some View { - Text("Mall Page") + ZStack(alignment: .topLeading) { + Text("Mall") + } } } diff --git a/demo/Views/User/Account/CouponView.swift b/demo/Views/User/Account/CouponView.swift index f22420b..dc48673 100644 --- a/demo/Views/User/Account/CouponView.swift +++ b/demo/Views/User/Account/CouponView.swift @@ -9,7 +9,9 @@ import SwiftUI struct CouponView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + ZStack { + Text("Coupon view") + } } } diff --git a/demo/Views/User/UserView.swift b/demo/Views/User/UserView.swift index ace3376..1930b65 100644 --- a/demo/Views/User/UserView.swift +++ b/demo/Views/User/UserView.swift @@ -11,6 +11,12 @@ struct UserView: View { @State private var showDetail = false @State private var showUserInfo = false + var grayBackground = Color.gray.opacity(0.2) + + init() { + print(UIScreen.main.bounds.width) + } + var body: some View { ScrollView(.vertical, showsIndicators: false) { VStack(spacing: 0) { @@ -23,7 +29,6 @@ struct UserView: View { Recommend } } - .padding(.bottom, 48) .animation(.spring, value: showDetail) } @@ -86,7 +91,6 @@ struct UserView: View { RoundedRectangle(cornerRadius: 12) .offset(y: 12) ) - .padding(.horizontal, 12) } @@ -101,9 +105,29 @@ struct UserView: View { } } } + .padding(.horizontal, 12) } - .padding(12) - .background(Color.gray.opacity(0.2)) + .padding(.top, 12) + .background( + Color.white + .overlay(alignment: .top) { + RoundedRectangle(cornerRadius: 12) + .fill(LinearGradient(colors: [Color.orange.opacity(0.3), grayBackground], startPoint: .top, endPoint: .bottom)) + .frame(height: 92) + } + ) + .clipped() + +// Rectangle() +// .fill(Color.white) +// .frame(height: 12) +// .overlay { +// RoundedRectangle(cornerRadius: 12) +// .fill(grayBackground) +// .frame(height: 24) +// .offset(y: 6) +// } +// .clipped() } var Notice: some View { @@ -142,8 +166,8 @@ struct UserView: View { .background(Color.white) .cornerRadius(8) .padding(.horizontal, 12) - .padding(.bottom, 12) - .background(Color.gray.opacity(0.2)) + .padding(.vertical, 12) + .background(grayBackground) } var OrderShow: some View { @@ -197,7 +221,7 @@ struct UserView: View { .cornerRadius(6) .padding(.horizontal, 12) .padding(.bottom, 12) - .background(Color.gray.opacity(0.2)) + .background(grayBackground) } var Coupons: some View { @@ -205,25 +229,29 @@ struct UserView: View { HStack { Spacer() ForEach(/*@START_MENU_TOKEN@*/0 ..< 5/*@END_MENU_TOKEN@*/) { _ in - VStack { - Image(systemName: "wallet.pass") - .resizable() - .frame(width: 24, height: 24) - .foregroundColor(Color.gray) - .overlay(alignment: .topTrailing) { - Circle() - .fill(Color.red.opacity(0.9)) - .frame(width: 20, height: 20) - .overlay { - Text("5") - .foregroundColor(Color.white) - .font(.system(size: 12)) - } - .offset(x: 12, y: -10) - } - Text("待付款") - .font(.system(size: 12)) - .foregroundColor(Color.gray) + NavigationLink { + CouponView() + } label: { + VStack { + Image(systemName: "wallet.pass") + .resizable() + .frame(width: 24, height: 24) + .foregroundColor(Color.gray) + .overlay(alignment: .topTrailing) { + Circle() + .fill(Color.red.opacity(0.9)) + .frame(width: 20, height: 20) + .overlay { + Text("5") + .foregroundColor(Color.white) + .font(.system(size: 12)) + } + .offset(x: 12, y: -10) + } + Text("待付款") + .font(.system(size: 12)) + .foregroundColor(Color.gray) + } } Spacer() } @@ -235,7 +263,7 @@ struct UserView: View { .cornerRadius(6) .padding(.horizontal, 12) .padding(.bottom, 12) - .background(Color.gray.opacity(0.2)) + .background(grayBackground) } let columns = [GridItem(.flexible(), spacing: 12), GridItem(.flexible(), spacing: 12)] @@ -262,7 +290,7 @@ struct UserView: View { } .padding(.horizontal, 12) .padding(.bottom, 12) - .background(Color.gray.opacity(0.2)) + .background(grayBackground) } }