嵌入式 UITextView 的圆角——什么是(错误地)保持圆角不透明?

Rounded Corners of an Embedded UITextView – What Is (Incorrectly) Keeping the Corners Opaque?

注意:为了清晰起见,我在找出解决方案(如下)后对其进行了编辑。

在界面生成器中,我将一个 UIView 嵌入到另一个 UIView 中,并将它们链接到各自的 UIViewController、EmbeddedViewController 和 MainViewController。然后我将一个 UITextView 放入嵌入式 UIView 并在 EmbeddedViewController 中创建对它的引用。

在 MainViewController 中,我以编程方式设置了 view.backgroundColor = UIColor.lightGray。在 EmbeddedViewController 中,我设置了 textView.backgroundColor = UIColor.whitetextView.layer.cornerRadius = 50。使用那些颜色,角落似乎没有变圆。但是当我设置 textView.backgroundColor = UIColor.red 时,很明显四舍五入有效,但是某些东西 的角 是不透明的白色。问题是,我不知道那是什么东西,在尝试了几种可能性之后,我仍然不知道我需要修复什么。

None 之前的问题似乎已经解决了这个特殊问题(即嵌入式 UIView 中 UITextView 圆角周围的不透明),但如果我遗漏了什么,请眉毛拍打我不够努力。否则,我会对界面构建器或编程解决方案感到满意。

这是一张图片(根据请求),其中 textView.backgroundColor = UIColor.red:

问题是我错误地认为我嵌入了一个 UITextView,而实际上我嵌入了一个 包含 UITextView 的 UIView。因此,不是要处理两个视图,而是实际上有三个视图:MainViewController 的视图、EmbeddedViewController 的视图和 EmbeddedViewController 的 textView。因此,要圆化 UITextView 的边角,这里有一个合理的方法:

在 EmbeddedViewController 中,设置 view.layer.cornerRadius = 50 并设置 view.clipsToBounds = true。由于 UITextView 是嵌入式 UIView 的子视图,textView 被裁剪到视图的边界。

这样,上面的白色区域就没有了