Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonghwinam/yhtagtextview
Easy-to-use SwiftUI component for detecting and making hashtags (#) and user tags (@) tappable.
https://github.com/yonghwinam/yhtagtextview
hashtags-parser swift swiftui usertag
Last synced: about 2 months ago
JSON representation
Easy-to-use SwiftUI component for detecting and making hashtags (#) and user tags (@) tappable.
- Host: GitHub
- URL: https://github.com/yonghwinam/yhtagtextview
- Owner: yonghwinam
- License: mit
- Created: 2024-08-29T05:40:31.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-29T08:45:13.000Z (4 months ago)
- Last Synced: 2024-10-13T02:21:09.363Z (3 months ago)
- Topics: hashtags-parser, swift, swiftui, usertag
- Language: Swift
- Homepage:
- Size: 1.08 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YHTagTextView
`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.
## Features
- 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.## Preview
## Requirements
- **iOS 15.0** or later
- **Swift 5.0** or later
- **SwiftUI**## Installation
### Swift Package Manager
1. In Xcode, go to `File > Swift Packages > Add Package Dependency...`.
2. Enter the following URL and click "Next":
`https://github.com/YourUsername/YHTagTextView.git`
3. Set the version rules, click "Next," then select the target you want to add the package to, and click "Finish."## Usage
```swift
import SwiftUI
import YHTagTextViewstruct 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")))
}
}
}
```## License
YHTagTextView is released under the MIT license. [See LICENSE](https://github.com/yonghwinam/YHTagTextView/blob/main/LICENSE) for details.