簡體   English   中英

在uibutton SWIFT周圍包裹文本

[英]Wrap a text around uibutton 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"
     }

}

我進入了模擬器

在模擬器中

預期結果:

預期結果

怎么了?

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

您正在使用另一個視圖的frame來設置此屬性,該屬性使用不同的坐標系。 記錄每個屬性的值(標簽的framebounds以及按鈕的frame ),以查看值如何相關以及如何從一個轉換為另一個。

相關文檔: 在視圖坐標系之間轉換

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM