在UIAlertView iOS 8 beta 5中无标题的UI问题
我在iOS 8上运行我们的应用程序时遇到与UIAlertView相关的问题。 我显示标题为nil的警报。它在iOS 7中工作正常,但现在UI看起来很奇怪。在UIAlertView iOS 8 beta 5中无标题的UI问题
我在这里附上截图。
我发现的一个解决方案是,当我提供空字符串@“”它看起来没问题。看下面的截图。但我不确定我提到的问题是测试版iOS 8版本中的错误,还是有其他更好的解决方案。即使有解决它的不准确,因为它在iOS的7
的iOS 7 - 显示与标题零警报视图。这里截图。
它一直是最好的做法,我使用initWithTitle:@""
为UIAlertView
,UIActionSheet
因为iOS 6中,因为我那段时间面临的一个设计问题,我用initWithTitle:nil
时。我试图找回来,我找不到原因究竟是什么。
从在iOS 8的屏幕截图,我觉得这是视图层次对UIAlertView中为iOS 8的变化,我认为Auto layout
可能在视图hierarachy实施,以及你可以看到messageLabel跳起来标题标签。
我无法确定,因为UIAlertView的视图层次结构是私有的。
UIAlertView类旨在按原样使用,并且不支持子类化 。该类的视图层次结构是私有的,并且不得修改 。
但是,我使用的代码: -
NSLog(@"%@",[self.alertView description]);
结果在iOS 7.1:在iOS 8
<UIAlertView: 0x7fb3c05535b0; frame = (18 263; 284 62); opaque = NO; layer = <CALayer: 0x7fb3c0519810>>
结果。0:
<UIAlertView: 0x7bf64840; frame = (0 0; 0 0); layer = <CALayer: 0x7bf648f0>>
我不知道为什么的iOS 8 UIAlertView中帧(0 0 0 0);
像迈克说,我想你应该学会使用UIAlertController
为iOS 8
我能与iOS 8中得到的最接近的是通过设置标题的消息,而不是:但是
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location field required." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
应该指出的是,UIAlertView
在iOS 8的弃用如果你打算使用iOS 7和iOS 8的单独代码路径,则应该使用UIAlertController
代替:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Location field required." message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alert animated:YES completion:nil];
我用两种方法都得到了相同的结果。
我设法得到体面的消息队列不加粗字体:
- 标题设置为@” “而不是零,并且
- (如果IOS8)在消息前加上”\ n“。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"\nLocation field required." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
请试试这个代码。 它在我身边 xcode版本9.2
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* btn1 = [UIAlertAction
actionWithTitle:@"OKAY"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
[self presentViewController:alert animated:YES completion:nil];