如何让UITextView背景透明?

发布于 2024-12-24 01:35:52 字数 221 浏览 2 评论 0原文

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

谢谢你!

In my application, I have a large text field that allows the user to input notes, but the only issue is that it does not blend into the background image that I have set. With the UITextField, you can set the border in the Interface Builder so that it does not have a white background, it has a transparent background making it show the background I have set behind it. I did not see this Border option with the UITextView, does anyone know how I can achieve the same effect? (I'm using Xcode 4.2 by the way).

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

来世叙缘 2024-12-31 01:35:52

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

带背景的文本视图

选择它并更改背景颜色

滑动不透明度滑块使背景透明。

You can change the opacity of the background in Interface Builder.

Text View with background

Select it and change the background colour

Slide the opacity slider to make the background transparent.

烟雨凡馨 2024-12-31 01:35:52

您可以使用以下代码 -

#import <QuartzCore/QuartzCore.h>

....


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

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

You can use following code-

#import <QuartzCore/QuartzCore.h>

....


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

decide color and border width as per your need.

旧话新听 2024-12-31 01:35:52

要将背景设置为 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.

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

To set the background to be transparent on a UITextView you can use

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

If you want to add a border to the UITextView then you would need to add that to the layer of the textView which you could do in the following way

[[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.

That should answer both your questions I think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文