ios - 如何从 UITextField 中排除文本以使 alpha 透明?
问题描述
我创建了一个将 alpha 设置为 0.2 的 uitextfield,问题是我找不到如何将 alpha 不透明度设置为仅应用于 UITextField 的背景,而不是应用于 UItextField 内的文本。我的代码片段:
self.emailInputField.text = "Enter your Email/Username"
self.passwordEmailInputField.text = "Enter your Password"
self.passwordEmailInputField.backgroundColor = .white
self.emailInputField.backgroundColor = .white
self.passwordEmailInputField.alpha = 0.1
self.emailInputField.alpha = 0.1
self.passwordEmailInputField.textColor = .gray
self.passwordEmailInputField.textColor = .gray
self.view.addSubview(self.emailInputField)
self.view.addSubview(self.passwordEmailInputField)
解决方案
扩展上面的评论:alpha
如果您的意图只是更改背景颜色,则不应将字段本身设置为 0.1。相反,backgroundColor
使用 alpha 初始化属性:
self.passwordEmailInputField.backgroundColor = .white.withAlphaComponent(0.1)
self.emailInputField.backgroundColor = .white.withAlphaComponent(0.1)
推荐阅读
- android - 对话框中的 GraphView 不起作用 - logcat 中的错误
- drupal - 单击事件链接时,在日历旁边的块中显示事件信息
- python - 带有 urlopen(..net/cé..) 的 UnicodeEncodeError
- orientdb - 如何在 OrientDB 中使查询与 OR 条件匹配
- python - 数字 3514524017891864227 是错误的吗?
- javafx - NoClassDefFoundError:tornadofx/视图
- c# - 如何在构建期间在 ASP.Net MVC 应用程序中合并第三方 api 调用
- c - Linux内核上的64位除法
- ios - 如何在swift中使用调用这个函数
- deployment - UWP。将出现在 Microsoft Store 中的应用的名称