Updating UIAlertView Message dynamically and newline character issue

前端 未结 5 1580
萌比男神i
萌比男神i 2021-01-22 00:21

I need to display multiple lines of text in the message of my UIAlertView. I have tried adding a \'\\n\', but it has no effect. It still displays: \"This is an examp....\".

5条回答
  •  深忆病人
    2021-01-22 01:06

    For newline use the \n newline character in your text like this:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"test" message:@"this is a message\nthis is a new line text" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    

    Even with setMessage this works:

    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setMessage:@"this is\na test"];
    [alert show];
    [alert release];
    

提交回复
热议问题