我正在尝试向我的UITextView添加背景图像,但似乎没有这样做的选项。我尝试添加一个imageView与图像作为子视图
self.bioTextView.delegate = self
let imgView = UIImageView(frame: self.bioTextView.frame)
imgView.image = #imageLiteral(resourceName: "text_field_bio")
self.bioTextView.addSubview(imgView)
但这也不起作用。 textView背景的颜色很清晰。我也尝试过将imgView发送到后面,但这也不起作用。
答案 0 :(得分:7)
添加foll_wing两行并检查一次
bioTextView.addSubview(imgView)
bioTextView.sendSubview(toBack: imgView)
或使用
bioTextView.backgroundColor = UIColor(patternImage: UIImage(named: "Image.png"))
<强>更新强>
let textView = UITextView(frame: CGRect(x: CGFloat(20), y: CGFloat(20), width: CGFloat(400), height: CGFloat(400 )))
textView.text = "this is a test \n this is test \n this is a test"
let img = UIImageView(frame: textView.bounds)
img.image = UIImage(named: "1.jpg")
textView.backgroundColor = UIColor.clear
textView.addSubview( img)
self.view.addSubview(textView)
textView.sendSubview(toBack: img)
您获得了输出