简体   繁体   中英

How to make UITextView background transparent?

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!

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

具有背景的文本视图

选择它并更改背景颜色

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM