UITextView - 如何让它看起来像IB?

时间:2021-05-19 19:45:19

I am initializing a text view from my code, not from the interface builder and it appears to be just a white rectangle. I want it to have the same rounded shape as is in the interface builder. How can I achieve this?

我正在从我的代码初始化文本视图,而不是从界面构建器初始化它看起来只是一个白色矩形。我希望它具有与界面构建器中相同的圆形形状。我怎样才能做到这一点?

The same question concerning UITextView.

关于UITextView的相同问题。

Thanks.

2 个解决方案

#1


The text view is rectangular even in IB. A UITextField has rounded corners. For that, just set the borderStyle property of UITextField to UITextBorderStyleRoundedRect

即使在IB中,文本视图也是矩形的。 UITextField有圆角。为此,只需将UITextField的borderStyle属性设置为UITextBorderStyleRoundedRect即可

#2


You maybe confusing UITextView with UITextField.

您可能会将UITextView与UITextField混淆。

UITextField has a optional rounded rectangle border. UITextView is just the text, no border. You have to bring your own border to the party and place it behind the UITextView.

UITextField有一个可选的圆角矩形边框。 UITextView只是文本,没有边框。您必须将自己的边框带到聚会并将其放在UITextView后面。

#1


The text view is rectangular even in IB. A UITextField has rounded corners. For that, just set the borderStyle property of UITextField to UITextBorderStyleRoundedRect

即使在IB中,文本视图也是矩形的。 UITextField有圆角。为此,只需将UITextField的borderStyle属性设置为UITextBorderStyleRoundedRect即可

#2


You maybe confusing UITextView with UITextField.

您可能会将UITextView与UITextField混淆。

UITextField has a optional rounded rectangle border. UITextView is just the text, no border. You have to bring your own border to the party and place it behind the UITextView.

UITextField有一个可选的圆角矩形边框。 UITextView只是文本,没有边框。您必须将自己的边框带到聚会并将其放在UITextView后面。