Search code examples
swifttextuibuttontitle

Forcing UIButton to have just one title line


I'm trying to force the UIButton to accept just one line of text, and if the title is too long I would like to have "..." at the end or in the middle of the title. but when I try out the code below, unfortunately, it doesn't work, it still gives multiline title text.

titleButton.titleLabel!.lineBreakMode = .byWordWrapping
titleButton.titleLabel!.numberOfLines = 1
titleButton.titleLabel!.textAlignment = .center

Solution

  • The main problem was the button style which was on the "plain", the magic happened after changing it to default!