在我的 UIView
上,有一个 UIImageView
和一个 UITextView
。
这个 UITextView
必须是透明的, 我们需要看到 imageView
。
我该如何做到这一点?
在我的 UIView
上,有一个 UIImageView
和一个 UITextView
。
这个 UITextView
必须是透明的, 我们需要看到 imageView
。
我该如何做到这一点?
如果你只想让UITextView的背景透明(而不是整个UITextView都透明),我认为你应该通过它从UIView继承的backgroundColor属性来实现。
像这样...
[yourTextView setBackgroundColor:[UIColor clearColor]];
这样应该能够解决问题。
但是,如果你想要将整个UITextView透明化,@taskinoor提到的alpha属性就非常完美。
您可以将文本视图的透明度设置为任何所需值。
myTextView.alpha = 0.5; // 50% 透明度
然后,您就完成了(如果我理解正确,您不必处理任何代码)!
我是这样使用的:
[textField setBackgroundColor:[UIColor clearColor]]; //clear background
[textField setBorderStyle:UITextBorderStyleNone]; //clear borders
Swift 4及更高版本
如果使用Swift 4,请使用以下代码:
yourTextView.backgroundColor = UIColor.clear