如何从一侧弯曲或扭曲 UILabel 文本

How to Bend or distortion a UILabel Text from one side

我使用了属性字符串和库,但找不到任何适合标签文本效果的解决方案。

任何人都可以建议我如何实现此功能吗?

谢谢

改编 How do I apply a perspective transform to a UIView? 中的代码,这里有一些示例 Swift 4 代码,将透视应用于标签,给出与您的图像相似的结果。

let pview = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 300))
pview.backgroundColor = .black
let plabel = UILabel(frame: CGRect(x: 0, y: 110, width: 250, height: 75))
pview.addSubview(plabel)
plabel.text = " ND420 "
plabel.textAlignment = .center
plabel.font = UIFont.boldSystemFont(ofSize: 72)
plabel.textColor = .orange
plabel.backgroundColor = .red
plabel.sizeToFit()
let layer = plabel.layer
var transform = CATransform3DIdentity
transform.m34 = 1.0 / -200
transform = CATransform3DRotate(transform, -45 * CGFloat.pi / 180, 0, 1, 0)
layer.transform = transform

运行 在操场上观看 pview

尝试分配给 transform.m34 的值和 CATransform3DRotate 中的旋转角度。负旋转角度(如上所示)使左侧变小,右侧变大。正角度则相反。