Reputation: 111
I have a multiline text with info button at the end of the text which is done with HStack at the moment.
HStack(spacing: 15) {
Image(uiImage: "questionMark")
.resizable()
.scaledToFit()
.frame(width: 15, height: 15)
Text("Neque porro quisquam est qui dolorem ipsum quia dolor sit amet.")
.fixedSize(horizontal: false, vertical: true)
}
which looks like this:
Goal:
But I want to have the button at the end of the last text like infoIcon should appear right after ipsum.
Note: What could be the best solution to achieve this and would like not to use UIKit in this regards?
Upvotes: 1
Views: 1527
Reputation: 18964
The possible solution is to add use Image constructor of Text but you can not add action only the image. Like this
struct ContentView: View {
var body: some View {
fullImageText
.onTapGesture {
}
}
var fullImageText: Text {
Text("Neque porro quisquam est qui dolorem ipsum quia dolor sit amet.") + Text(Image("edit"))
}
}
Another solution is to use NSMutableAttributedString
wrap with UIViewRepresentable
. Here is demo : https://stackoverflow.com/a/62169577/14733292
Upvotes: 3