在uibutton SWIFT周围包裹文本

cmi*_*mii 5 uibutton uitextview ios swift

我需要在按钮周围显示文字.

在我的视图控制器中,我有:

class myViewController: UIViewController {

    @IBOutlet var backButton: UIButton!
    @IBOutlet var myTitle: UITextView!

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let exclusionPath:UIBezierPath = UIBezierPath(rect: backButton.frame)
        myText.textContainer.exclusionPaths=[exclusionPath]
    }

     override func viewDidLoad() {
         super.viewDidLoad()
         myTitle.text="Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu"
     }

}
Run Code Online (Sandbox Code Playgroud)

我进入了模拟器

在模拟器中

预期结果:

预期结果

怎么了?

Dim*_*ima 2

的文档将exclusionPaths其描述为:An array of UIBezierPath objects representing the exclusion paths inside the receiver's bounding rectangle. Default value: nil.

您正在使用frame另一个视图的来设置此属性,该属性使用不同的坐标系。记录每个属性(frame以及bounds标签和frame按钮)的值,以查看这些值如何相互关联以及如何从一个属性转换为另一个属性。

相关文档:视图坐标系之间的转换