iPhone UITextField背景色 [英] iPhone UITextField background color
问题描述
我无法使用 borderStyle = UITextBorderStyleRoundedRect
来控制 UITextField
的背景颜色。使用此边框样式, backgroundColor
属性似乎只能控制沿圆角矩形内边缘的非常窄的线条。该字段的其余部分保持白色。
I am unable to control the background color of a UITextField
with a borderStyle= UITextBorderStyleRoundedRect
. With this border style the backgroundColor
property only seems to control a very narrow line along the inner edge of the rounded rectangle. The rest of the field remains white.
但是,如果 borderStyle
设置为 UIBorderStyle = UITextBorderStyleBezel
然后 UITextField
的整个背景由其 backgroundColor
属性控制。
However, if the borderStyle
is set to UIBorderStyle=UITextBorderStyleBezel
then the entire background of the UITextField
is controlled by its backgroundColor
property.
这是一个功能吗?有没有办法控制 UITextField
的 backgroundColor
,并带有 borderStyle = UITextBorderStyleRoundedRect
?
Is this a feature? Is there a way to control the backgroundColor
of a UITextField
with a borderStyle=UITextBorderStyleRoundedRect
?
推荐答案
要更改UITextField中的背景颜色,首先需要使用不同风格的文本字段在Interface Builder中或以编程方式呈现圆形样式(例如无边框样式)。
To change the background color in a UITextField you first need to use a different style of text field to the "rounded" style (such as the "no border" style) either in Interface Builder or programmatically.
然后,您可以使用
textField.backgroundColor = backgroundColor;
其中textField是你的UITextField,而backgroundColor是UIColor。
where textField is your UITextField, and backgroundColor is a UIColor.
作为进一步的提示 - 如果你想恢复圆角外观,你首先需要
As a further tip- if you wish to restore the rounded corners appearance, you will first need to
#import <QuartzCore/QuartzCore.h>
然后设置
textField.layer.cornerRadius=8.0f;
textField.layer.masksToBounds=YES
此功能可以使用
这篇关于iPhone UITextField背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!