我正在寻找一种简单的方法,以类似下面这样的非常简单的消息框为例,使用NSAttributedString
:
NSString *new_item = [NSString stringWithFormat:@"<span style=\"font-family: Helvetica Neue; font-size: 12.0\">%@</span>", @"MOTD HTML String downloaded from website"];
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[new_item dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MOTD"
message:attrStr
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
我的代码接收一个从服务器下载的HTML格式字符串,确保文本大小适合屏幕,然后尝试将NSAttributedString发送到UIAlertView。但是UIAlertView不喜欢这样做。有没有最简单的方法解决这个问题?(非HTML格式MOTD不是选项)
UIAlertView
和UIAlertController
都不支持属性字符串,那么你要么找到一个第三方替代品,要么自己动手写一个。 - rmaddy