UIButton with two lines of text in the title (numberOfLines=2)

后端 未结 6 1909
面向向阳花
面向向阳花 2021-01-30 15:42

I\'m trying to make a UIButton that has two lines of text in its titleLabel. This is the code I\'m using:

    UIButton *titleButton = [[UIButton all         


        
6条回答
  •  长发绾君心
    2021-01-30 16:11

    You don't need to add a UILabel to the UIButton. That's just extra objects and work.

    Set these properties on the titleLabel of your button.

    button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    button.titleLabel.numberOfLines = 2;//if you want unlimited number of lines put 0
    

    Swift:

    button.titleLabel!.lineBreakMode = NSLineBreakMode.ByWordWrapping
    button.titleLabel!.numberOfLines = 2//if you want unlimited number of lines put 0
    

提交回复
热议问题