iOS-用另一种形式的文本替换文本
我正在为用户创建一个登录页面,并且有一个 UITextField 供用户输入密码。最后我还有一个摘要页面,它返回用户信息,包括密码。我正在尝试将密码更改为显示为“安全”或使用星号而不是文本。例如:
passInput.text = @"password"
changed to: ********;
我使用以下代码来完成任务:
NSString *password = passInput.text;
NSRange range = NSMakeRange(0,passInput.text.length);
NSString *formattedPassword = [password stringByReplacingCharactersInRange:range withString:@"*"];
[sumPassword setText:newPassText];
问题是它只返回一颗星,而不是我认为应该返回的 8 颗星。
我缺少什么?
I'm creating a login page for users, and I have a UITextField
for users to input a password. I also have a summary page at the end, which gives back the users information including the password. I'm trying to change the password to display as "secure" or with stars instead of the text. For example:
passInput.text = @"password"
changed to: ********;
I am using the following code to accomplish the task:
NSString *password = passInput.text;
NSRange range = NSMakeRange(0,passInput.text.length);
NSString *formattedPassword = [password stringByReplacingCharactersInRange:range withString:@"*"];
[sumPassword setText:newPassText];
The problem is that it returns only one star and not 8 stars as I would think it should.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置:
以便在该字段中书写时显示点而不是字母。
否则你可以像这样:
或者...
You could just set:
so that it shows dots instead of letters when writing in that field.
Otherwise you could make it like:
or...
我假设您需要给它提供与范围内的字符一样多的 * ,否则它会取出整个范围,并将其替换为给定的字符串。 ,您必须将其更改为
换句话说,对于给定的
password = @"password";
示例I assume you need to give it as many *'s as you have characters in the range, otherwise its taking out that entire range, and replacing it with the string given. In other words, you would have to change it to
for the given example of
password = @"password";