如何使UITextView背景透明?

时间:2012-01-03 17:46:58

标签: iphone xcode background uitextview

在我的应用程序中,我有一个允许用户输入注释的大文本字段,但唯一的问题是它没有混合到我设置的背景图像中。使用UITextField,您可以在Interface Builder中设置边框,使其不具有白色背景,它具有透明背景,使其显示我在其后面设置的背景。我没有看到UITextView的这个Border选项,有谁知道我怎么能达到同样的效果? (我顺便使用Xcode 4.2)。

谢谢!

3 个答案:

答案 0 :(得分:3)

您可以在Interface Builder中更改背景的不透明度。

Text View with background

Select it and change the background colour

Slide the opacity slider to make the background transparent.

答案 1 :(得分:2)

要在UITextView上将背景设置为透明,您可以使用

UITextView* myTextView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,280,180)];
[myTextView setBackgroundColor:[UIColor clearColor]];

如果你想为UITextView添加一个边框,你需要将它添加到textView的图层,你可以用以下方式做到这一点

[[myTextView layer] setCornerRadius:15.0f]; //You don't need to set this but it will give the view rounded corners.
[[myTextView layer] setBorderWidth:1.0f]; //again you pick the value 1 is quite a thin border
[[myTextView layer] setBorderColor:[[UIColor blackColor] CGColor]]; //again you can choose the color.

我认为这应该回答你的两个问题。

答案 2 :(得分:2)

您可以使用以下代码 -

#import <QuartzCore/QuartzCore.h>

....


textView.layer.borderWidth = 5.0f;
textView.layer.borderColor = [[UIColor grayColor] CGColor];

根据您的需要决定颜色和边框宽度。

相关问题