Post

Replies

Boosts

Views

Activity

How can I accomplish this?
Hi all, I am having an issue here that I can't seem to figure out. What I want to happen is the user can select an image by clicking on the 'addPhoto' button, which does work. the problem is after the image is selected the other 'addPhoto" buttons disappear from the screen. I want the user to be able to upload up to 5 images but with the other disappearing once the first image is selected obviously that cannot happen. Does anyone have recommendations on the best way to implement this? Here is my code: struct PostItemView: View { @State private var selectedImage: UIImage? @State var postImage: Image? @State var description = "" @State var imagePickerPresented = false var body: some View { NavigationView { VStack(spacing: 10) { HStack { CircularProfileImageView(size: .medium) Text("User Name") .font(.system(size: 18,weight: .semibold)) }.padding(.top,30) .padding() Spacer() Text("Add Photos (max. of 5)") .padding() .font(.system(size: 18,weight: .semibold)) ScrollView(.horizontal) { HStack{ if postImage == nil { Button(action: {imagePickerPresented.toggle()}, label: { AddPhotoButton() }).sheet(isPresented: $imagePickerPresented, onDismiss: loadImage,content: { ImagePicker(image: $selectedImage) }) Button(action: {imagePickerPresented.toggle()}, label: { AddPhotoButton() }).sheet(isPresented: $imagePickerPresented, onDismiss: loadImage,content: { ImagePicker(image: $selectedImage) }) Button(action: {imagePickerPresented.toggle()}, label: { AddPhotoButton() }).sheet(isPresented: $imagePickerPresented, onDismiss: loadImage,content: { ImagePicker(image: $selectedImage) }) Button(action: {imagePickerPresented.toggle()}, label: { AddPhotoButton() }).sheet(isPresented: $imagePickerPresented, onDismiss: loadImage,content: { ImagePicker(image: $selectedImage) }) Button(action: {imagePickerPresented.toggle()}, label: { AddPhotoButton() }).sheet(isPresented: $imagePickerPresented, onDismiss: loadImage,content: { ImagePicker(image: $selectedImage) }) } else if let image = postImage { image .resizable() .scaledToFill() .frame(width: 120,height: 120) .clipped() } } .foregroundColor(.black) .padding(4) } Spacer() Text("Give us some details:") .font(.system(size: 18,weight: .semibold)) .padding() TextField("Enter your information", text: $description) .padding() Spacer() Button(action: {}, label: { Text("Post my Item") }) .font(.system(size: 20,weight: .semibold)) .frame(width: 300, height: 50) .background(Color.green) .cornerRadius(8) .foregroundColor(.white) } .navigationTitle("Post Item") .navigationBarTitleDisplayMode(.inline) } } } extension PostItemView { func loadImage() { guard let selectedImage = selectedImage else { return } postImage = Image(uiImage: selectedImage) } } Thanks in advance.
2
0
426
Aug ’23
How to prevent my custom header from being pushed up
Hi all, I have been racking my brain about this for hours now and cannot seem to get it figured out. I have created a custom header using a Swift UI View. When I put the HeaderView onto say my Menu View it is fine until I start adding content. I want to add navigation links in my Menu View to navigate my app. At that time, the shape part of my header start to get bumped up out of position but the text stays where it should. How do I prevent the header from moving at all? I want it to be in a fixed position on each screen. I will be using the same header just with different text on each screen. Here is my HeaderView struct HeaderView: View { let title: LocalizedStringKey var bgColor: Color var body: some View { GeometryReader { geometry in ZStack { Ellipse() .fill(self.bgColor) .frame(width: geometry.size.width * 1.4, height: geometry.size.height * 0.30) .position(x: geometry.size.width / 2.00, y: geometry.size.height * 0.035) .edgesIgnoringSafeArea(.all) VStack{ Text(self.title) .font(.title) .fontWeight(.bold) .foregroundColor(Color.green) .padding(.top,20) Spacer() } } } } } Here is my Menu View: struct MenuView: View { @StateObject var viewModel = MenuViewViewModel() init() {} var body: some View { NavigationView{ VStack{ HeaderView(title: "Menu", bgColor: Color.green.opacity(0.3)) HStack{ Image(systemName: "bell.fill") NavigationLink("Notifications", destination: NotificationsView()) } HStack{ Image(systemName:"person.crop.circle.fill") NavigationLink("Profile", destination: ProfileView()) } HStack{ Image(systemName: "puzzlepiece.fill") NavigationLink("Projects", destination: ProjectsView()) } } } } } I can provide screenshots of what happens after I do this if need be. Thanks in advance.
0
0
744
Jul ’23
Getting Error " No exact matches in reference to static method 'buildExpression'"
Hello, this is my first post. I am new to programming and am trying to self teach. I am building a TOS view in my app and I keep getting an error. Here is the code: import Foundation import UIKit import SwiftUI struct TermsOfServiceView: View { var body: some View { VStack(alignment: .leading) { Text("Terms of Service").font(.title) Text("Welcome to Ag Central! By using our app, you agree to the following terms of service:").font(.subheadline).padding(.top, 10) SwiftUI.Group { Text("1. Your data and information").font(.headline).padding(.top, 20) Text("a) When you use our app, we collect certain information about you, including your name, email address, and any content you share on the platform.").padding(.top, 10) Text("b) We may use your information to improve our app and to provide you with a better experience. However, we will never sell or share your data with third parties without your permission.").padding(.top, 10) Text("2. User Content").font(.headline).padding(.top, 20) Text("a) You are solely responsible for the content you post on our app. You agree not to post any content that violates any laws or infringes on the rights of others.").padding(.top, 10) Text("b) We reserve the right to remove any content that we feel is inappropriate or violates our policies.").padding(.top, 10) Text("3. Intellectual Property Rights").font(.headline).padding(.top, 20) Text("a) We own all of the intellectual property rights, including any trademarks, rights, and patents associated with our app.").padding(.top, 10) Text("b) You may not use our intellectual property without our express permission.").padding(.top, 10) Text("4. Indemnification").font(.headline).padding(.top, 20) Text("a) You agree to indemnify and hold harmless our company and its affiliates against any claims, lawsuits, or damages arising from your use of our app.").padding(.top, 10) Text("5. Changes to the Terms").font(.headline).padding(.top, 20) Text("a) We reserve the right to update or change these terms of service at any time. We will notify you of any changes via email or in-app notification.").padding(.top, 10) } .padding(.horizontal, 20) .multilineTextAlignment(.leading) Spacer() } .padding() } } Hoping someone can explain what I am doing wrong here? Thanks in advance
1
0
2.0k
Jun ’23