DSFSecureTextField

带有“可见性”按钮的 NSSecureTextField。

为什么

有时能够看到密码字段的内容会很有帮助。DSFSecureTextField 在现有的 NSSecureTextField 中添加了一个可见性按钮,允许您的用户显示或隐藏字段的内容。

您可以选择动态地从控件中删除该按钮(例如,如果您希望能够让用户通过首选项选择是否显示密码)

集成

用法

界面构建器

  1. 将安全文本字段拖到画布中
  2. 将控件的 Custom Class 字段设置为 DSFSecureTextField
  3. 完成!

代码

由于 DSFSecureTextField 继承自 NSSecureTextField,因此您可以像创建 NSSecureTextField 一样创建它

演示

Demos 文件夹中有一个非常简单的项目。

配置

参数 类型 描述
allowPasswordInPlainText Bool 如果为 true,允许控件显示密码的纯文本表示形式。如果您希望能够控制用户是否可以选择(例如,通过首选项)使密码可见,则此功能很有用。
displayToggleButton Bool 如果为 true,则在控件内部显示一个按钮(一个眼睛),允许用户在安全和纯文本输入之间切换
visibility 可见性 如果为 .plainText,则以纯文本形式显示密码。

allowPasswordInPlainText

一个布尔标志,指示是否允许该字段以纯文本显示密码。

如果为 true,允许控件显示密码的纯文本表示形式。如果您希望能够控制用户是否可以选择(例如,通过首选项)使密码可见,则此功能很有用。

displayToggleButton

如果为 true,则在密码字段中嵌入一个“眼睛”按钮,允许用户切换密码的可见性。

visibility

可见性标志表示字段中文本的可见性

描述
.secure 内容以安全方式显示(例如,●●●●●●●●
.plainText 内容以纯文本形式显示(例如,gr00vy!.

许可

MIT License

Copyright (c) 2023 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.