Saturday, November 21, 2026
HomeiOS Developmentios - Customized line spacing for UIButton in Swift

ios – Customized line spacing for UIButton in Swift

[ad_1]

I’ve programmatically created a easy giant UIButton that shows 5 traces of textual content with my Swift code beneath.


Query

Utilizing code, how do I modify the attributes of the UIButton to both enhance or lower the road spacing between every line of textual content?


Code

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        addMyButton()
    }
    
    func addMyButton() {
        let myButton = UIButton(sort: UIButton.ButtonType.customized)
        myButton.setTitle("FirstnSecondnThirdnFourthnFifth", for:UIControl.State())
        myButton.titleLabel!.lineBreakMode = .byWordWrapping
        myButton.titleLabel!.textAlignment = .middle
        myButton.titleLabel!.font = UIFont(identify: "HelveticaNeue", measurement: 20)
        myButton.titleEdgeInsets = UIEdgeInsets(prime: 0, left: 0, backside: 0, proper: 0)
        myButton.backgroundColor = UIColor.purple
        myButton.body = CGRect(x: 50, y: 50, width: 300, top: 600)
        view.addSubview(myButton)
    }
    
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments