-6

How to set a multiline as title of a UIButton in iPhone programming ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Raju
  • 3,459
  • 12
  • 37
  • 30
  • 2
    Agree this should be closed as a dupe. Raju - please can you try searching rather than just posting new questions. You are wasting everyone elses time. It might also help the general goodwill if you marked a few of the questions you asked as answered. – Rog Jun 08 '09 at 09:25
  • possible duplicate of [How do you add multi-line text to a UIButton?](http://stackoverflow.com/questions/604632/how-do-you-add-multi-line-text-to-a-uibutton) – phi Sep 03 '12 at 08:57
  • 1
    Possible duplicate of [How do you add multi-line text to a UIButton?](https://stackoverflow.com/questions/604632/how-do-you-add-multi-line-text-to-a-uibutton) – Cœur Oct 16 '18 at 06:32

4 Answers4

7
someButton.lineBreakMode = UILineBreakModeWordWrap;

Be sure to try to get in the habit of consulting the documentation before posting a question. Apple's documentation is pretty comprehensive, and things like this generally get covered.

Matt Ball
  • 6,608
  • 1
  • 32
  • 31
3

Hi,

There is a property of UIButton called lineBreakMode which will allow you to add multiline titles. The two main things I would set it to are UILineBreakModeWordWrap or UILineBreakModeCharacterWrap.

UILineBreakModeWordWrap wraps the last word and UILineBreakModeCharacterWrap wraps at the lastcharcter.

looks like: instanceOfUIButton.lineBreakMode = UILineBreakModeWordWrap;

or instanceOfUIButton.lineBreakMode = UILineBreakModeCharacterWrap;

hope that's what your after

Aitul
  • 2,982
  • 2
  • 24
  • 52
abe
  • 4,046
  • 6
  • 29
  • 33
1

Please don't use subviews.

someButton.lineBreakMode = UILineBreakModeWordWrap; 

this is the right way to do this. There is a tutorial on this for the German community!

http://bedifferently.wordpress.com/2011/11/16/uibutton-bearbeite-den-titel-teil-1/

eeerahul
  • 1,629
  • 4
  • 27
  • 38
Tristan
  • 11
  • 1
  • Please do more than just post a link; summarize the link so that this answer can stand on its own in case that link breaks. – George Stocker Nov 06 '12 at 19:25
-2

UIButton doesn't display multiple lines. The way to make it do so is to addSubview a UILabel to the button

AlexC
  • 9,657
  • 17
  • 64
  • 98