如何在 swiftUI 的末尾文本字段添加 % 符号
我想制作一个自定义文本字段,该字段将显示金额和(%)符号 任何人都可以告诉我我如何才能实现这一目标。 如果我输入12,则应自动插入12%的
Uikit,就像TextField.text =“(text)%”
struct UiTextFieldRepresentable: UIViewRepresentable {
@Binding var text: String
func makeUIView(context: Context) -> some UIView {
let textField = UITextField(frame: .zero)
textField.placeholder = "Enter your text"
textField.text = "\(text) %"
return textField
}
func updateUIView(_ uiView: UIViewType, context: Context) {
}
}
此代码的问题是在我开始写作之前它显示为%符号。 我想要的是,当我开始在现场写作时,应该将%符号发布
I want to make a custom text field which will display the amount and (%) symbol
can anyone please tell me how can i acheive this.
if i enter 12 it should auto insert 12%
in UIKit it will be like textField.text = "(text) %"
struct UiTextFieldRepresentable: UIViewRepresentable {
@Binding var text: String
func makeUIView(context: Context) -> some UIView {
let textField = UITextField(frame: .zero)
textField.placeholder = "Enter your text"
textField.text = "\(text) %"
return textField
}
func updateUIView(_ uiView: UIViewType, context: Context) {
}
}
issue with this code is it is showing % sign before i start writing.
all i want want is when i start writing in the field it should postfix the % sign
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,我发挥了作用,在右侧将图像放置为修复我的问题的百分比
for this i made a function and on right side put a image as percentage that fixed my issue
对于此类情况,请显示您的代码。因为我不确定这是一个实际问题,也许您在提出这个问题之前甚至还没有开始编码。
你到底在做什么?要显示
%
符号,只需将其放入文本中(不存在格式问题,它不是特殊符号等):您将得到呈现的视图:
For the cases like this, please show your code. Because I'm not sure this is an actual question, maybe you haven't even started coding before asking it.
What exactly are you doing? To display the
%
symbol, just put in in the text (there're no formatting issues, it's not a special symbol etc):And you'll get your view rendered: