Wrap text around uibutton SWIFT

I need to display the text around the button.

In my opinion, the controller has:

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

in the simulator

Expected Result:

expected result

What's wrong?

+5
source share
1 answer

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

You use the frame another view to set this property, which uses a different coordinate system. Write down the values ​​of each of these properties ( frame and bounds your label and frame your button) to find out how the values ​​relate and how to translate them from one to another.

Related documentation: Conversion between view coordinate systems

+2
source

Source: https://habr.com/ru/post/1209154/


All Articles