天天看點

iOS 設定狀态欄

解決方案是

添加 

View controller-based status bar appearance = NO;  必須是這個

然後再 AppDelegate.cpp

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

添加一行   

 [[UIApplication sharedApplication] setStatusBarHidden:NO];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

可是就算這樣放置,也是有問題的  白字出來了,黑底還是沒有出來。

因為我是自定義的navigationbar,是以才用了下圖的第二種解決方案:

以下是我的實作代碼:

    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, -DeviceStatusBarHeight, SCREEN_WIDTH, DeviceStatusBarHeight)];

    view.backgroundColor = [UIColor blackColor];

    [self.navigationController setNavigationBarHidden:YES];

    UINavigationBar * bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0,DeviceStatusBarHeight, SCREEN_WIDTH, 44)];

    [bar setBackgroundImage:[UIImage imageNamed:@"綠色條.png"] forBarMetrics:UIBarMetricsDefault];

    [bar addSubview:view];

    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];

    label.backgroundColor = [UIColor clearColor];

    label.text = @"通訊錄";

    label.textColor = [UIColor whiteColor];

    label.textAlignment = NSTextAlignmentCenter;

    UINavigationItem * item = [[UINavigationItem alloc]init];

    [item setTitleView:label];

    [bar pushNavigationItem:item animated:YES];

    [self.view addSubview:bar];

繼續閱讀