YHTagTextView
is a custom SwiftUI view that automatically detects hashtags (#
) and user tags (@
) in a string, converting them into tappable links. When a hashtag or user tag is tapped, a specified callback function is triggered, allowing you to handle the event as needed.
- Automatically detects hashtags (
"#example"
) and user tags ("@user"
) within a string. - Tappable tags that trigger specified callback functions.
- Customizable tag color.
- Easy-to-use API for quick integration.
- iOS 15.0 or later
- Swift 5.0 or later
- SwiftUI
- In Xcode, go to
File > Swift Packages > Add Package Dependency...
. - Enter the following URL and click "Next":
https://github.com/YourUsername/YHTagTextView.git
- Set the version rules, click "Next," then select the target you want to add the package to, and click "Finish."
import SwiftUI
import YHTagTextView
struct ContentView: View {
@State private var showAlert = false
@State private var alertMessage = ""
var body: some View {
VStack {
YHTagTextView(
string: "Check out #SwiftUI and connect with @JohnDoe for more details!",
tagColor: .blue,
touchedHashTag: { hashtag in
alertMessage = "You tapped on the hashtag: \(hashtag)"
showAlert = true
},
touchedUserTag: { usertag in
alertMessage = "You tapped on the user tag: \(usertag)"
showAlert = true
})
}
.padding()
.alert(isPresented: $showAlert) {
Alert(title: Text("Tag Selected"), message: Text(alertMessage), dismissButton: .default(Text("OK")))
}
}
}
YHTagTextView is released under the MIT license. See LICENSE for details.