How do I word wrap a UIButton title in code?


#1

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


(Adrian Zubarev) #2

If I remember correctly the property on the UIButton is called `.lineBreakMode`, which accepts an enum.

···

--
Adrian Zubarev
Sent with Airmail

Am 28. Januar 2017 um 00:46:18, Mutlu Qwerty via swift-users (swift-users@swift.org(mailto:swift-users@swift.org)) schrieb:

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

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users