[swift-users] How do I word wrap a UIButton title in code?

Mutlu Qwerty tcavalli at outlook.com
Fri Jan 27 17:46:18 CST 2017


How do I make a UIButton wrap lines in the Title?  Here is a sample code:


   func testing() {

        let aButton = UIButton(type: .system)

        aButton.lineWrap = true  //How do I make aButton wrap lines?

        aButton.setTitle("123\n456\n789", for: .normal)

        self.view.addSubview(aButton)

    }


What I want to see is a button like this:

 ---

|123|

|456|

|789|

 ---


This can be done in the Storyboard by selecting "Word Wrap" in the Button's Control - Line Break attribute.  But I am creating my UIButtons in code and can not find the proper syntax to code this.


Thomas Cavalli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170127/fbfd3d7b/attachment.html>


More information about the swift-users mailing list