我正在使用新的UIAlertController来显示警报.我有这个代码:
// nil titles break alert interface on iOS 8.0, so we'll be using empty strings
UIAlertController *alert = [UIAlertController alertControllerWithTitle: title == nil ? @"": title message: message preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle: cancelButtonTitle style: UIAlertActionStyleCancel handler: nil];
[alert addAction: defaultAction];
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootViewController presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
现在我想更改标题和消息字体,颜色,大小等.什么是最好的方法呢?
编辑: 我应该插入整个代码.我为UIView创建了一个类别,我可以为iOS版本显示正确的警报.
@implementation UIView (AlertCompatibility)
+( void )showSimpleAlertWithTitle:( NSString * )title
message:( NSString * )message
cancelButtonTitle:( NSString * )cancelButtonTitle
{
float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue]; …Run Code Online (Sandbox Code Playgroud) 我有一个UITableView自定义UILabel标题和另一个副标题,以便将文本对齐.
我的数据来自Web服务,这是我在分析和存储NSArray的NSDictionary.一些标题或副标题可以是零/空文本.为此,我把它放在try/catch中.
我的桌子中的一条线让我的应用程序粉碎,我无法弄清楚原因.
我认为其中一个(标题/副标题)返回,NSDictionary 但我为我的对象做了一个日志打印,对于我来说[UILabel text],似乎一切都好.
异常和堆栈跟踪:
2014-04-29 10:47:55.985 Cellular Radar[3226:60b] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:55.993 Cellular Radar[3226:60b] -[Home tableView:willDisplayCell:forRowAtIndexPath:], exception.reason: -[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:55.999 Cellular Radar[3226:60b] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:56.006 Cellular Radar[3226:60b] CRASH:
-[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:56.062 Cellular Radar[3226:60b] Stack Trace:
(
0 CoreFoundation 0x30e02feb …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种简单的方法来使用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];
Run Code Online (Sandbox Code Playgroud)
我上面的代码采用从服务器下载的HTML格式的字符串,确保文本大小适合屏幕,然后尝试发送NSAttributedString到UIAlertView.但UIAlertView不喜欢这个.这个问题最简单的方法是什么?(非HTML格式的MOTD不是一个选项)
我在将 SF 符号添加到标题时遇到问题。SF 符号与标题文本重叠有人可以帮助我吗
func uialert(){
let alert = UIAlertController(title: "New User Created", message: " A new user has been created.", preferredStyle: .alert)
let imgTitle = UIImage(systemName: "checkmark.circle")
let imgViewTitle = UIImageView(frame: CGRect(x: 120, y: 10, width: 30, height: 30))
imgViewTitle.image = imgTitle
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
alert.view.addSubview(imgViewTitle)
self.present(alert, animated: true)
}
Run Code Online (Sandbox Code Playgroud) 是否有办法为uialertview中的某些特定单词着色?我的意思是,我可以将RED这个词换成红色,同时将GREEN换成绿色吗?

有人能以正确的方式带我吗?
ios ×4
objective-c ×3
uialertview ×3
colors ×1
ios13 ×1
ios8 ×1
sf-symbols ×1
swift ×1
uitableview ×1