Updating UIAlertView Message dynamically and newline character issue

前端 未结 5 1583
萌比男神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 00:58

    Here is some simple code to resize the messages in an alert. Note that the alert's frame needs to be large enough. You can pad the initial alert with a few newlines.

    for (UILabel *l in alertView.subviews){
        if ([l isKindOfClass:[UILabel class]]){
            float w = l.frame.size.width;
            [l setNumberOfLines:0];
            [l sizeToFit];
            CGRect r = l.frame;
            r.size.width = w;
            l.frame = r;
        }
    }
    

提交回复
热议问题