在uibutton SWIFT周围包裹文本

时间:2022-11-29 11:51:57

I need to display a text around a button.

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

In my view controller I have:

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

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"
     }

}

I get in the simulator

我进入了模拟器

在uibutton SWIFT周围包裹文本

The expected result:

预期结果:

在uibutton SWIFT周围包裹文本

What's wrong?

1 个解决方案

#1


2  

The documentation for exclusionPaths describes it as: An array of UIBezierPath objects representing the exclusion paths inside the receiver's bounding rectangle. Default value: nil.

exclusionPaths的文档将其描述为:UIBezierPath对象的数组,表示接收器边界矩形内的排除路径。默认值:nil。

You are using the frame of another view to set this property, which uses a different coordinate system. Log the values of each of these properties (frame and bounds of your label, and frame of your button) to see how the values relate and how to translate from one to the other.

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

Relevant documentation: Converting Between View Coordinate Systems

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

#1


2  

The documentation for exclusionPaths describes it as: An array of UIBezierPath objects representing the exclusion paths inside the receiver's bounding rectangle. Default value: nil.

exclusionPaths的文档将其描述为:UIBezierPath对象的数组,表示接收器边界矩形内的排除路径。默认值:nil。

You are using the frame of another view to set this property, which uses a different coordinate system. Log the values of each of these properties (frame and bounds of your label, and frame of your button) to see how the values relate and how to translate from one to the other.

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

Relevant documentation: Converting Between View Coordinate Systems

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