问题
Is it possible to have a textfield's placeholder text opaque while its background is set to be transparent, eg. if I choose some background color, and set alpha to some value, like this:
the placeholder text becomes transparent as well. But I want it opaque. So, is this achievable, preferably using storyboard ? Or at least through the code.
If it is unclear what I am trying to achieve, just let me know , and I'll post an image with an example.
回答1:
You can set the color's transparency instead of the UITextField's alpha. Open the color drop down and select "Other". A color picker will open up. At the bottom of the color picker you can change the opacity.
回答2:
In Swift you can obtain the placeholder element with:
let placeHolder = textField.value(forKey: "placeholderLabel") as! UILabel
placeHolder.textColor = .blue
placeHolder.isOpaque = true
and make all customizations you prefeer..
来源:https://stackoverflow.com/questions/46575839/having-textfield-background-transparent-but-placeholder-text-opaque