是否可以将 UIAlertView 之类的内容添加到今天的小部件?我向小部件添加了一个 IBAction 和一个 UIAlertView,但什么也没发生。
是否可以制作更大的小部件?我在 Size-Inspector 中更改了高度,但它根本不起作用。
是否可以将 UIAlertView 之类的内容添加到今天的小部件?我向小部件添加了一个 IBAction 和一个 UIAlertView,但什么也没发生。
是否可以制作更大的小部件?我在 Size-Inspector 中更改了高度,但它根本不起作用。
简短的回答是否定的,您不能在今天的小部件中显示警报。UIAlertController 以模态方式呈现,您的小部件无法访问整个屏幕。它有大约 3/4 的最大屏幕高度可以显示。
这是一些快速执行此操作的基本代码(用于未来的项目):
let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
self.presentViewController(alertController, animated: true, completion: nil)
你需要UIAlertController
在iOS8上使用,参考在这里。
例如:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"I am an AlertView" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];