创建带有纯白色文本的半透明 uibutton
Create semi transparent uibutton with solid white text
我正在尝试创建类似于以下内容的按钮:
我尝试为 alpha 提供白色文本颜色,但我得到以下信息:
编辑:
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])
我正在尝试创建类似于以下内容的按钮:
我尝试为 alpha 提供白色文本颜色,但我得到以下信息:
编辑:
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])