How to add line break for UILabel?

后端 未结 21 2138
失恋的感觉
失恋的感觉 2020-11-29 14:53

Let see that I have a string look like this:

NSString *longStr = @\"AAAAA\\nBBBBB\\nCCCCC\";  

How do I make it so that the UILabel disp

21条回答
  •  Happy的楠姐
    2020-11-29 15:31

    On Xcode 6, you can just use \n even inside a string when using word wrap. It will work. So for example:

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, screenRect.size.width, 50)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"This will be on the first line\nfollowed by a line under it.";
    label.lineBreakMode = UILineBreakModeWordWrap;
    label.numberOfLines = 0;
    

提交回复
热议问题