簡體   English   中英

iOS 7導航欄高度

[英]iOS 7 navigation bar height

是否可以在iOS 7中更改導航欄高度?

為什么我需要導航欄:在我的視圖中有一個透明的導航欄,其他元素的正確位置沒有任何問題;

我不想創建一個虛假的“導航欄” - 在這種情況下,我需要自己設置所有位置。

//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;
}

在您的應用代表中

UINavigationController *NavController=[[UINavigationController alloc]initWithRootViewController:HomeViewController];
[NavController.navigationBar setBounds:CGRectMake(10, 30, 40, 10)];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM