例如,使用以下代码很容易使用常规标签进行背景剪裁:
var coloredBackground : UIView!
coloredBackground = UIView(frame: view.bounds)
coloredBackground.backgroundColor = .blue
coloredBackground.center = view.center
view.addSubview(coloredBackground)
let imageView = UIImageView(frame: coloredBackground.bounds)
imageView.image = UIImage(named: "image")
coloredBackground.addSubview(imageView)
let label = UILabel(frame: coloredBackground.bounds)
label.text = "stackoverflow"
label.font = UIFont(name: "Helvetica", size: 30)
coloredBackground.addSubview(label)
imageView.mask = label
但是我似乎无法将其应用于UITextView