Friday, May 3, 2024
HomeiOS Developmentios - Concatenate some strings, each needs to be clickable individually in...

ios – Concatenate some strings, each needs to be clickable individually in swiftUI


Right here is the piece of code, half is commented,
within the first half, textual content components from array are in VStack, and each seems in new line. however on clicking it offers particulars in regards to the clicked array factor.
However in 2nd half, textual content Is concatenated and visual within the paragraph. However on click on it’s unable to indicate the main points for the clicked factor.
I simply want the paragraphic illustration of the textual content and every factor clickable.
right here is the code

//import SwiftUI
//
//struct ContentView: View {
//    let dummyStrings = [
//        "Lorem ipsum dolor sit amet*",
//        "consectetur adipiscing elit*",
//        "sed do eiusmod tempor incididunt*",
//        "ut labore et dolore magna aliqua*",
//        "Ut enim ad minim veniam*",
//        "quis nostrud exercitation ullamco*",
//        "laboris nisi ut aliquip ex ea commodo consequat*",
//        "Duis aute irure dolor in reprehenderit*",
//        "in voluptate velit esse cillum dolore*",
//        "eu fugiat nulla pariatur*"
//    ]
//    
//    var physique: some View {
//        ScrollView {
//            VStack(alignment: .main, spacing: 10) {
//                // Concatenate all strings right into a single steady textual content
//                Textual content(dummyStrings.joined(separator: " "))
//                    .font(.physique)
//                    .foregroundColor(.blue)
//                    .modifier(ClickableText(traces: dummyStrings) { string in
//                        print("Clicked:", string)
//                    })
//            }
//            .padding()
//        }
//    }
//}
//
//// View modifier to make every line of textual content individually tappable
//struct ClickableText: ViewModifier {
//    let traces: [String]
//    let motion: (String) -> Void
//    
//    func physique(content material: Content material) -> some View {
//        // Use GeometryReader to find out the dimensions of every line of textual content
//        GeometryReader { proxy in
//            VStack(spacing: 0) {
//                ForEach(traces, id: .self) { line in
//                    Textual content(line)
//                        .onTapGesture {
//                            motion(line)
//                        }
//                        .body(width: proxy.dimension.width, alignment: .main)
//                        .contentShape(Rectangle()) // Make complete Textual content space tappable
//                }
//            }
//        }
//    }
//}
//
//struct ContentView_Previews: PreviewProvider {
//    static var previews: some View {
//        ContentView()
//    }
//}
//

//------------------For Testing use -------------------

import SwiftUI

struct ContentView: View {
    let dummyStrings = [
        "1Lorem ipsum dolor sit amet",
        "2consectetur adipiscing elit",
        "3sed do eiusmod tempor incididunt",
        "4ut labore et dolore magna aliqua",
        "5Ut enim ad minim veniam",
        "6quis nostrud exercitation ullamco",
        "7laboris nisi ut aliquip ex ea commodo consequat",
        "8Duis aute irure dolor in reprehenderit",
        "9in voluptate velit esse cillum dolore",
        "10 eu fugiat nulla pariatur"
    ]
    
    var physique: some View {
        let concatenatedText = dummyStrings.joined(separator: " ")
        
        return ScrollView {
            Textual content(concatenatedText)
                .font(.physique)
                .foregroundColor(.blue)
                .lineSpacing(5)
                .onTapGesture {
                    // Deal with faucet gesture right here (e.g., print tapped portion)
                    print("Textual content tapped")
                }
                .padding()
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

 



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments