Post

Replies

Boosts

Views

Activity

Why I am not able to click button and back to ViewController?
I am use SecondView as programmatically, I am click the button in ViewController and open SecondView controller, but I want to back to ViewController. I do not have storyboard in SecondView and I want to click the closeButton and back to ViewController. My code work but when I click the close button it is not work. Any idea? import UIKit class SecondView: UIViewController {       var closeButton = UIButton()   override func viewDidLoad() {     super.viewDidLoad()           closeButton.addTarget(self, action: #selector(dismissActionSheet), for: .touchUpInside)   }       @objc func dismissActionSheet() {     self.navigationController?.popViewController(animated: true)    } }
1
0
400
Jul ’21
How can I hide bottom navigation bar when I click the list item?
I have bottom navigation bar and in fist view I have list item, when I click the list item, it is open detail view, but bottom navigation bar still stay in detail view, I want to hide navigation bar when I click open the detail view. Is it possible? ContentView: struct TabView : View {   @State private var selection = 0   @State var index = 0       var body: some View{           VStack(spacing: 0){               ZStack{                 ListView()                     .opacity(self.index == 0 ? 1 : 0)         }               HStack{                   Button(action: {                       self.index = 0                     }) {                       HStack(spacing: 6){                         Image("List")                              .foregroundColor(self.index == 0 ? Color("blue") : .black)                           if self.index == 0{                               Text("List")                 .foregroundColor(Color("blue"))             }                         }           .padding(.vertical,10)           .padding(.horizontal)           .background(self.index == 0 ? Color("tabbar-background") : Color.clear)           .clipShape(Capsule())         }                   Spacer(minLength: 0)                   Button(action: {                       self.index = 1                     }) {                       HStack(spacing: 6){                         Image("SecondList")                              .foregroundColor(self.index == 1 ? Color("blue") : .black)                           if self.index == 1{                               Text("SecondList")                 .foregroundColor(Color("blue"))             }                         }           .padding(.vertical,10)           .padding(.horizontal)           .background(self.index == 1 ? Color("tabbar-background"): Color.clear)           .clipShape(Capsule())         }}}     .edgesIgnoringSafeArea(.bottom)   } } ListView: struct ListView: View {   var body: some View {     VStack{       ScrollView(.vertical, showsIndicators: false, content: {         VStack(spacing: 15){             RowView(docs: docs)                       }         }         }   }     } } struct RowView: View {   @State var docs: Datas   var body: some View {          HStack(spacing: 15){       NavigationLink(destination:  ListDetailView(docs: docs)) {       HStack{       Image(docs.image)         .resizable()         .frame(width: 64, height: 48)                }       }     }     .padding(.horizontal)         } } ListDetailView: import SwiftUI struct ListDetailView: View {   @State var docs: Datas       var body: some View {                 ZStack{       Image(docs.image)         .resizable()         .aspectRatio(contentMode: .fit)             }              } } struct ListDetailView_Previews: PreviewProvider {   static var previews: some View {     ListDetailView(docs: datas[0])           } }
0
0
994
Aug ’21
How can I resize bottom sheet height?
I am using bottom sheet for my app, and it is work correctly, but I want to use the half bottom sheet, is it possible?      Image( "color")               .resizable()               .frame(width:45, height: 45)               .sheet(isPresented: $showSheet, content: {                   ScreenView()                  })
1
0
1.3k
Jul ’22
How can I add costom emoji to example chat app?
I have simple chat app, and I want to use simple emoji in this chat app, my emoji is located in EmojiView an when I click the emoji button, I want to add in live chat, but I do not know how I will forward for it, I was look at many resources but I did not find any example on internet, is it possible to do it? import SwiftUI struct MessageDetailsView: View {   var body: some View {     HomeMessageDetails()}} struct MessageDetailsView_Previews: PreviewProvider {      static var previews: some View {     MessageDetailsView()      }} struct HomeMessageDetails : View {   @State var message = ""   @StateObject var allMessages = Messages()   @State private var emojiData = false   var body: some View{           ZStack {       VStack{         ScrollView(.vertical, showsIndicators: false, content: {           ScrollViewReader{reader in             VStack{               ForEach(allMessages.messages){message in                 ChatBubble(message: message)               }                .onChange(of: allMessages.messages) { (value) in                 if value.last!.chatMessages{                   reader.scrollTo(value.last?.id)}}}             .padding([.horizontal,.bottom])}})         HStack {             HStack{             TextField("Message", text: self.$message)             Button(action: {             emojiData = true             }, label: {               Image("emoji")             }) .sheet(isPresented: $emojiData) {           EmojiView()         } }           .padding(.vertical, 10)           .padding(.horizontal)                Button(action: {             allMessages.messages.append(Message(id: Date(), message: message, chatMessages: true))                           message = ""           }, label: {             Image("reply")              })   }         .padding(.horizontal)       }} }} struct ChatBubble : View {   var message : Message   var body: some View{     HStack(alignment: .top,spacing: 10){       if message.chatMessages{         Text(message.message)           .foregroundColor(Color("black))         }             else{         Text(message.message)             .foregroundColor(.white)  }}     .id(message.id)}} struct Message : Identifiable,Equatable{   var id : Date   var message : String   var chatMessages : Bool    } class Messages : ObservableObject{   @Published var messages : [Message] = []   init() {           let strings = ["Hii","Hello !!!!"]     for i in 0..<strings.count{       messages.append(Message(id: Date(), message: strings[i], chatMessages: i % 2 == 0 ? true : false))}}           func writeMessage(id: Date,message: String,chatMessages: Bool){           messages.append(Message(id: id, message: message, chatMessages: chatMessages))}} struct EmojiView: View {   var body: some View {  Button(action: {             }, label: {               Image("smile_emoji")                           }) }}
0
0
402
Feb ’22
How can I give the permission for WKWebView to access phone library?
I have a small app and I am using WKWebView for my app, so in WebView I have sign in, when I sign to WebView I have to import image, documents etc to WebView, so I have to use permission in my app, is it possible to apply WKWebView in below code? import SwiftUI import WebKit struct ContentView: View { var body: some View { ZStack{ WebView() } } } struct WebView: UIViewRepresentable { func makeUIView(context: Context) -> WKWebView { WKWebView(frame: .zero) } func updateUIView(_ view: WKWebView, context: UIViewRepresentableContext<WebView>) { let request = URLRequest(url: URL(string: "https://codepen.io/login")!) view.load(request) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .navigationBarHidden(true) } }
0
0
581
Jun ’22