Alert换行,根据特殊字符换行

来源:互联网 发布:网络release是什么意思 编辑:程序博客网 时间:2024/06/01 10:02

在alert提示框中,需要根据分号换行,先看一种复杂的方法

    NSString* str=@"123;456;789";    NSArray *arry=[str componentsSeparatedByString:@";"];    NSString *str2=[[NSString alloc]init];    for (NSString *mystr in arry) {        str2=[str2 stringByAppendingFormat:@"\n%@",mystr];    }    NSLog(@"%@",str2);

再看一种简单的方法

tips = [tips stringByReplacingOccurrencesOfString:@";" withString:@"\n"];UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"更新提示!" message:tips preferredStyle:UIAlertControllerStyleAlert];

放到alertcontroller中左对齐,效果如下

这里写图片描述
alerter中左对齐效果,参考具体微博:
http://blog.csdn.net/lee727n/article/details/78053822