【问题标题】:How to make UITextView background transparent?如何使 UITextView 背景透明?
【发布时间】:2012-01-03 17:46:58
【问题描述】:

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

谢谢!

【问题讨论】:

  • 'Border width' 和 'Border color' 更好。

标签: iphone xcode background uitextview


【解决方案1】:

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

【讨论】:

  • 非常感谢,帮了大忙!
  • 没问题!很高兴我能帮上忙!
【解决方案2】:

您可以使用以下代码-

#import <QuartzCore/QuartzCore.h>

....


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

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

【讨论】:

    【解决方案3】:

    要在 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.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-06
      • 2011-09-17
      • 2011-02-18
      • 2016-10-24
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多