I have simple chat app, and it is work for image picker, but I have custom image view and it fetch the images from internet, I want to use them instead of the image picker in my phone, but I did not find any solution, is there any idea about it?
struct Home: View {
@State var message = ""
@State var imagePicker = false
@State var imgData: Data = Data(count: 0)
@StateObject var allMessages = Messages()
var body: some View {
ZStack {
VStack {
VStack {
// Displaying Message
ScrollView(.vertical, showsIndicators: true) {
ScrollViewReader { reader in
VStack(spacing: 20) {
ForEach(allMessages.messages) { msg in
ChatBubble(msg: msg)
}
.onChange(of: allMessages.messages) {
value in
if value.last!.myMsg {
reader.scrollTo(value.last?.id)
}}}}}}}
.clipShape(RoundedRectangle(cornerRadius: 35))}
VStack {
HStack(spacing: 15) {
HStack(spacing: 15) {
TextField("Message", text: $message)
Button(action: {
// toggling image picker
imagePicker.toggle()
}) {
Image(systemName: "paperclip.circle.fill")
.font(.system(size: 22))
.foregroundColor(.gray)}
.background(Color.black.opacity(0.06))
.clipShape(Capsule())
if message != "" {
Button(action: {
withAnimation(.easeIn) {
allMessages.messages.append(Message(id: Date(), message: message, myMsg: true, profilePic: "p1", photo: nil))
}
message = ""
}) {
Image(systemName: "paperplane.fill")
.font(.system(size: 22))
.foregroundColor(Color("Color"))
// rotating the image
.rotationEffect(.init(degrees: 45))
.clipShape(Circle())}}}
.padding(.bottom)
.padding(.horizontal)
.background(Color.white)
.animation(.easeOut)
}
.fullScreenCover(isPresented: $imagePicker, onDismiss: {
if imgData.count != 0 {
allMessages.writeMessage(id: Date(), msg: "", photo: imgData, myMsg: true, profilePic: "p1")
}
}) {
ImagePicker(imagePicker: $imagePicker, imgData: $imgData)
}}}}
struct ChatBubble: View {
var msg: Message
var body: some View {
HStack(alignment: .top, spacing: 10) {
if msg.myMsg {
if msg.photo == nil {
Text(msg.message)
.padding(.all)
.background(Color.black.opacity(0.06))
.clipShape(BubbleArrow(myMsg: msg.myMsg))
} else {
Image(uiImage: UIImage(data: msg.photo!)!)
.resizable()
.frame(width: UIScreen.main.bounds.width - 150, height: 150)
.clipShape(BubbleArrow(myMsg: msg.myMsg))
}
Image(msg.profilePic)
.resizable()
.frame(width: 30, height: 30)
.clipShape(Circle())
} else {
Image(msg.profilePic)
.resizable()
.frame(width: 30, height: 30)
.clipShape(Circle())
if msg.photo == nil {
Text(msg.message)
.foregroundColor(.white)
.padding(.all)
.background(Color("Color"))
.clipShape(BubbleArrow(myMsg: msg.myMsg))
} else {
Image(uiImage: UIImage(data: msg.photo!)!)
.resizable()
.frame(width: UIScreen.main.bounds.width - 150, height: 150)
.clipShape(BubbleArrow(myMsg: msg.myMsg))}}}
.id(msg.id)}}
struct RoundedShape: Shape {
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 35, height: 35))
return Path(path.cgPath)
}
}
struct Message: Identifiable, Equatable {
var id: Date
var message: String
var myMsg: Bool
var profilePic: String
var photo: Data?
}
class Messages: ObservableObject {
@Published var messages: [Message] = []
init() {
let strings = ["Hii", "Hello!!", "What's up?", "What Are you doing?", "Nothing, just enjoying quarantine holidays.. you??", "Same :))", "Ohhh", "What about your country?", "Very very bad..", "Ok, be safe.", "Ok", "Bye"]
for i in 0..<strings.count {
// simple logic for two side message View
messages.append(Message(id: Date(), message: strings[i], myMsg: i % 2 == 0, profilePic: i % 2 == 0 ? "p1" : "p2"))
}
}
func writeMessage(id: Date, msg: String, photo: Data?, myMsg: Bool, profilePic: String) {
messages.append(Message(id: id, message: msg, myMsg: myMsg, profilePic: profilePic, photo: photo))
}
}
CustomImageView:
struct CustomImageView: View {
private let threeColumnGrid = [
GridItem(.flexible(minimum: 40)),
GridItem(.flexible(minimum: 40)),
GridItem(.flexible(minimum: 40)),
]
var body: some Scene {
LazyVGrid(columns: threeColumnGrid, alignment: .center) {
ForEach(model.imageNames, id: \.self) { item in
GeometryReader { gr in
Image(item)
.resizable()
.scaledToFill()
.frame(height: gr.size.width)
}
.clipped()
.aspectRatio(1, contentMode: .fit)
}
}
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have a register view and when I complete my register, I want to pass register data in form from WebView, is there any way to do it?
I have a simple app and it has simple properties, like user register to app, and it connect the webview, webview has payment also, but I am search on internet, and many people says like that apps will reject by apple, any idea?
I have TabView in ContentView and I want to add TabView for OnboardingView in OtherView, every things work, but it is throw error for TabView in OtherView like "Trailing closure passed to parameter of type 'Int' that does not accept a closure" I do not know why? Any idea?
ContentView:
struct TabView : View {
var body: some View{
VStack(spacing: 0){
.......
}
OtherView:
VStack {
TabView {
ForEach(onboardingData) { onboardingItem in
OnboardingCard(onboardingItem: onboardingItem)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
.indexViewStyle(PageIndexViewStyle (backgroundDisplayMode:
.always))
.foregroundColor(.white)
}
I have searchable properties in my project, everythings work, but it is looking bad when I search any items, it show "cancel" title inside of the search bar, how can I hide it?
.searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always))
Hi every one, if you build a mobile project with SwiftUI, is it possible to use the app for sub version of IOS like iPhone 6s devices ?
I was use pod install for my project and it throw error like below.
"[!] The MyApp [Debug] target overrides the FRAMEWORK_SEARCH_PATHS build setting defined in Pods/Target Support Files/Pods-MyApp/Pods-MyApp.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the $(inherited)` flag, or
- Remove the build settings from the target."
even I try to fix the xcode with $(inherited) in project target and project, it is still same. I don't know what I miss?
I want to use searchbar for name, but it is throw an arror like " Value of type 'Text' has no member 'searchable'" any idea?
@State private var searchText = ""
Text(data.name)
.font(.custom("Helvetica Neue", size: 14))
.searchable(text: $searchText)
I have SwiftUI project, and I want to use register for my project, it throw an error as a "Function is unused" for signUp in this line of code:
Button {
self.viewModel.signUp
} label: {
Text("Register")
.padding()
}
I do not know why?
struct Register: View {
@ObservedObject private var viewModel: RegisterViewModel
@State var pushActive = false
init(state: AppState) {
self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)
}
var body: some View {
Button {
self.viewModel.signUp
} label: {
Text("Register")
.padding()
}
}
viewmodel:
class RegisterViewModel: ObservableObject {
@Published var email: String = ""
@Published var password: String = ""
@Published var state: AppState
private var cancellableBag = Set<AnyCancellable>()
private let authAPI: AuthAPI
init(authAPI: AuthAPI, state: AppState) {
self.authAPI = authAPI
self.state = state
}
func signUp() {
authAPI.signUp(email: email, password: password)
.receive(on: RunLoop.main)
.map(resultMapper)
.store(in: &cancellableBag)
}
}
}
I have custom search bar and custom circle image in toolbar, when I click the circle image, I want to navigate new SwiftUI. Any idea will be appreciated.
ImageView:
VStack(alignment: .leading, spacing:0){
HStack(spacing: 0){
TextField("Search", text: $search)
.padding(.vertical,5)
.padding(.horizontal)
.background(Color.gray.opacity(0.090))
.cornerRadius(30)
.frame(width: 330, height: 32)
Image("imgage")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 32, height: 32)
.clipShape(Circle())
.overlay(Circle().stroke(Color("fig"), lineWidth: 1))
}
}
ContentView:
var body: some View {
//I have tabview here//
}
I have sidebar menu, I want to integrate with my app. In app, I have tabbar, sidebar menu not work correctly with tab bar. Any idea will be appreciated?
var body: some View {
SideMenuView()
TabView(selection: $selection){
PeopleView()
.tabItem {
selection == 0 ? Image("people-selected") : Image("people")
}
.tag(0)
AnimalView()
.tabItem {
selection == 1 ? Image("animal-selected") : Image("animal")
}
.tag(1)
PlantsView()
.tabItem {
selection == 2 ? Image("plants-selected") : Image("plants")
}
.tag(2)
}
I have a SwiftUI project, since long time I try to customize my project toolbar in SwiftUI, but SwiftUI 2.0 not support it. When new version of SwiftUI will release? Any idea?
I have new project and I added "pod 'AssetsPickerViewController', '~> 2.0' " to pod file and import AssetsPickerViewController to my project file, but still throw this error? Any idea?
I have searchBarTextDidEndEditing func , but when I want to call searchBar in other func like that
`search.searchBar.showLoading()`
it throw error like that "Value of type 'UISearchBar' has no member 'showLoading'"
searchBarTextDidEndEditing func:
`
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
self.search.animationController(forDismissed: self)
self.search.automaticallyShowsSearchResultsController = false
}`
I want to use segue when I click the forget password icon , Iit may open "ForgotPasswordEmailCheckController" view, my code is running but it throw error like "Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyApp.LoginViewController 0x7fa962b13730> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key forgotPassword.'" I don't know why?
ForgotPasswordEmailCheckController:
class ForgotPasswordEmailCheckController: UIViewController, UITextFieldDelegate {
var storyboardId: String {
return (value(forKey: "ForgotPasswordEmailCheckController") as? String)!
}
LoginViewController:
@IBAction func forgotPassword(_ sender: Any) {
let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
guard let forgotPasswordEmailCheckCotroller = mainStoryboard.instantiateViewController(identifier: "ForgotPasswordEmailCheckController") as?
ForgotPasswordEmailCheckController else {
print("Not correct password")
return
}
navigationController?.pushViewController(forgotPasswordEmailCheckCotroller, animated: true)
}