【发布时间】:2017-02-21 00:03:30
【问题描述】:
为了在我的UITextView 中获得背景图像,我在代码中创建了一个UIImageView,用我想要的图像填充它,将其添加为UITextView 的subView,并将其发送到背部。这适用于某些屏幕,但在其他屏幕上看起来像这样。
。
查看上面的UITextFields,了解它的外观。
这是我的代码。
let img = UIImageView(frame: self.bioTextView.bounds)
img.image = #imageLiteral(resourceName: "text_field_bio")
self.bioTextView.backgroundColor = UIColor.clear
self.bioTextView.addSubview(img)
self.bioTextView.sendSubview(toBack: img)
self.bioTextView.textContainerInset.left = 10
如何让图像的右侧剪辑到尾随边界,使其不会超出 UITextview。
编辑: 这是一个编辑,包括当我包含此代码时发生的情况的图像。
self.bioTextView.layer.borderWidth = 1
self.bioTextView.layer.borderColor = UIColor.red.cgColor
【问题讨论】:
-
bioTextView的界限是什么?我的第一直觉是它比其他文本字段宽得多,因为它似乎剪裁了左侧。 -
bioTextView 与 TextFields 共享前沿和后沿
-
textviews也是代码添加的?可能是添加imageView时,textView的bounds不正确。
-
文本视图没有添加到代码中。它们在 Storyboard 中布局,我用 IBOutlet 引用它们
-
@GabeSpound 你可以使用这个代码
bioTextView.layer.borderWidth = 1和bioTextView.layer.borderColor = UIColor.red.cgColor并发布图像结果,看看发生了什么
标签: ios swift uiimageview uitextview