我正在尝试添加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);
}