gpt4 book ai didi

ios - 将 UITextField 背景设置为 .clearColor 时,为什么我的 UITextField 占位符会消失?

转载 作者:可可西里 更新时间:2023-11-01 00:11:15 24 4
gpt4 key购买 nike

使用 Xcode v7.2 - iOS v9.2 - iPhone5S swift

我正在尝试创建一个透明的 UITextField,带有浅灰色占位符文本。

我用过:

self.userEmailTextField.backgroundColor = UIColor.clearColor()

占位符文本消失,但在使用 whiteColorblueColor 背景时出现。

白色背景:

userEmailTextField with .whiteColor Background

清晰的背景:

userEmailTextField with .clearColor Background

最佳答案

由于背景颜色清晰,占位符不可见。您可以通过像这样设置占位符颜色来检查它...

在 swift ...

if let _ = self.placeholder{
self.txtField.attributedPlaceholder = NSAttributedString(string:self.placeholder!,
attributes:[NSForegroundColorAttributeName: UIColor.whiteColor()])
}

在目标语言中...

[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

关于ios - 将 UITextField 背景设置为 .clearColor 时,为什么我的 UITextField 占位符会消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34647627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com