簡體   English   中英

用純白色文本創建半透明的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])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM