How do I create a transparent UITextField?

26,005

Solution 1

Objective-C

If you only want to make the background (rather than the whole UITextView) transparent, I believe you should be do this via the backgroundColor property it inherits from UIView.

As such...

[yourTextView setBackgroundColor:[UIColor clearColor]];

...should hopefully do the trick.

If however, you want to make the whole UITextView transparent, the alpha property @taskinoor mentions is perfect.

Solution 2

You can set the alpha of text view to any desired value.

myTextView.alpha = 0.5;    // 50% transparent

Solution 3

I use in this way:

[textField setBackgroundColor:[UIColor clearColor]]; //clear background
[textField setBorderStyle:UITextBorderStyleNone]; //clear borders

Solution 4

Swift 4 and higher

For Swift 4 use this:

yourTextView.backgroundColor = UIColor.clear
Share:
26,005
good guy
Author by

good guy

working on iPhone/iPad app's

Updated on July 23, 2020

Comments

  • good guy
    good guy almost 4 years

    On my 1) UIView one (2) UIImageView will be on this (3) UITextView.

    This UITextView must be Transparent and we have to view the imageView.

    How can I do this?

  • John Parker
    John Parker over 13 years
    Won't the alpha property affect everything (text included)? Then again, perhaps that's what he wants. (Hard to tell from the question.)
  • taskinoor
    taskinoor over 13 years
    Ya, text also be changed. It guess that's what he is looking for. Otherwise I have misunderstood the question.
  • good guy
    good guy over 13 years
    hi Taskinoor i am looking for UITextView must be Transparent without effecting the Text on it,
  • taskinoor
    taskinoor over 13 years
    @Nandakishore, try the answer of middaparka then. You can create UIColor with specific alpha value by using UIColor colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha method.