我正在尝试添加 UIToolBar,但它没有出现在 iPhone 上。它虽然显示在 iPad 上。我究竟做错了什么?
UIToolbar *webToolBar = [[UIToolbar alloc]init];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
fixedSpace.width = 20.0;
[webToolBar setItems:[NSArray arrayWithObjects:backButton, forwardButton, flexibleSpace, refreshButton, fixedSpace, stopButton, nil]animated:NO];
webToolBar.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height - 44, [[UIScreen mainScreen]bounds].size.width, 44);
}
else
{
UIBarButtonItem *fixedSpaceiPad = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpaceiPad.width = 460.0;
fixedSpace.width = 50.0;
webToolBar.frame = CGRectMake(0, 660, 703, 44);
[webToolBar setItems:[NSArray arrayWithObjects:backButton, forwardButton, fixedSpaceiPad, refreshButton, fixedSpace, stopButton, nil]animated:NO];
}
webToolBar.delegate = self;
[webToolBar setBarStyle:UIBarStyleDefault];
webToolBar.tintColor = kfbBlue;
webToolBar.hidden = NO;
[webToolBar sizeToFit];
[self.view addSubview:webToolBar];
我也试过这样放置。通过此实现,它在 iPhone 4S、5 和 5S 上显示在正确的位置,但在 6 或 6 Plus 上根本不显示。
CGSize result = [[UIScreen mainScreen] bounds].size;
NSInteger y = [[UIScreen mainScreen]bounds].size.height - 44;
NSInteger screenWidth = [[UIScreen mainScreen]bounds].size.width;
NSLog(@"Screen height = %f", [[UIScreen mainScreen]bounds].size.height);
NSLog(@"y = %ld and width = %ld", y, screenWidth);
fixedSpace.width = 20.0;
// webToolBar.frame = CGRectMake(0, y, screenWidth, 44);
[webToolBar setItems:[NSArray arrayWithObjects:backButton, forwardButton, flexibleSpace, refreshButton, fixedSpace, stopButton, nil]animated:NO];
if (result.height == 480)
{
webToolBar.frame = CGRectMake(0, 372, 320, 44);
}
else if (result.height == 568)
{
webToolBar.frame = CGRectMake(0, 460, 320, 44);
}
else if (result.height == 667) {
webToolBar.frame = CGRectMake(0, 623, 375, 44);
}
else if (result.height == 736) {
webToolBar.frame = CGRectMake(0, 692, 414, 44);
}