是否可以在iOS 7中更改导航栏高度?
为什么我需要导航栏: 在我的视图上有一个透明的导航栏,其他元素的位置没有任何问题;
我不想创建一个虚假的“导航栏” - 在这种情况下,我需要自己设置所有职位。
答案 0 :(得分:3)
//make real nav bar invisible
self.navigationBar.barTintColor = [UIColor clearColor];
UIImage* transparentImage = [UIImage emptyImageWithSize:CGSizeMake(self.navigationBar.frame.size.width, 1) andBackgroundColor:[UIColor clearColor]];
[self.navigationBar setBackgroundImage:transparentImage forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = transparentImage;
然后
UINavigationBar* fakeNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, neededHeight)];
fakeNavigationBar.barTintColor = [UIColor whiteColor];
[self.navigationBar insertSubview:fakeNavigationBar atIndex:0];
,其中
+ (UIImage*)emptyImageWithSize:(CGSize)size andBackgroundColor:(UIColor*)color
{
CGRect frameRect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(ctx, color.CGColor); //image frame color
CGContextFillRect(ctx, frameRect);
UIImage* resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
答案 1 :(得分:1)
在您的app delegate
中UINavigationController *NavController=[[UINavigationController alloc]initWithRootViewController:HomeViewController];
[NavController.navigationBar setBounds:CGRectMake(10, 30, 40, 10)];