How to add line break for UILabel?

后端 未结 21 2201
失恋的感觉
失恋的感觉 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条回答
  •  广开言路
    2020-11-29 15:23

    It seems wrong to me to change the label frame sizes especially when using autolayout. Using the appendFormat method seems more appropriate. Here is my example:

    NSMutableString *list = [[NSMutableString alloc] init];
    NSArray *textArray = @[@"AAAA", @"BBBB"];
    for (NSString *string in textArray) {
        [list appendFormat:@"%@\n", string.mutableCopy];
    }
    self.label.text = list;
    self.label.numberOfLines = 0;
    

提交回复
热议问题