gpt4 book ai didi

ios - 创建带有纯白色文本的半透明 uibutton

转载 作者:行者123 更新时间:2023-11-28 12:39:01 28 4
gpt4 key购买 nike

我正在尝试创建类似于以下内容的按钮: enter image description here

我试图给 alpha 提供白色文本颜色,但我得到以下信息:

enter image description here

编辑:

textfield.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 0.7)
textfield.textColor = .white

上面的代码给出了第二张图片。但是上面的图片看起来很难看。

如何创建像第一张图片那样的 uitextfield?

编辑:
完整的解决方案:

txtLogin.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.1)
txtLogin.textColor = .white
txtLogin.attributedPlaceholder = NSAttributedString(string:"Username",
attributes:[NSForegroundColorAttributeName: UIColor(red: 245, green: 245, blue: 241, alpha: 0.7)])
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 20))
txtLogin.leftView = paddingView
txtLogin.leftViewMode = UITextFieldViewMode.always

let layer: CALayer! = txtLogin.layer
layer.cornerRadius = 4.0
layer.borderWidth = 0

问候

最佳答案

您需要做的是将按钮的 alpha 设置为您想要的点。因此,例如,这将具有半透明背景和白色文本颜色:

button.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.1)
button.textColor = .white
button.attributedPlaceholder = NSAttributedString(string:"placeholder text",
attributes:[NSForegroundColorAttributeName: UIColor.white])

关于ios - 创建带有纯白色文本的半透明 uibutton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40005380/

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