Having textfield background transparent, but placeholder text opaque

折月煮酒 提交于 2021-01-28 13:50:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!