最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS狀態(tài)欄、導(dǎo)航欄的一些筆記分享

 更新時間:2019年04月08日 11:19:29   作者:QiShare  
這篇文章主要給大家分享了關(guān)于iOS中狀態(tài)欄、導(dǎo)航欄的一些筆記,文中通過示例代碼介紹的非常詳細(xì),對各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧

前言

IOS的界面分為狀態(tài)欄和導(dǎo)航欄,如下圖所示:

狀態(tài)欄與導(dǎo)航欄的位置如上圖,我們可以通過[UIApplication sharedApplication].statusBarFrame.size獲取狀態(tài)欄的size(一般沒有劉海時的高度為20,有劉海時的高度為44)。

通過self.navigationController.navigationBar.frame.size獲取導(dǎo)航欄的size(一般高度為44,大標(biāo)題時高度為xyz,當(dāng)然也可以通過自定義來改變導(dǎo)航欄樣式)。

***ps:***在我們通過[nav.navigationBar setBarTintColor:[UIColor lightGrayColor]];來設(shè)置導(dǎo)航欄顏色時,將導(dǎo)致導(dǎo)航欄和狀態(tài)欄背景色均變?yōu)闇\灰色。

1. 狀態(tài)欄內(nèi)容是否高亮

狀態(tài)欄內(nèi)容包括信號、時間、電量等,只有兩種顏色樣式(黑或白)。iOS開發(fā)過程中提供修改狀態(tài)欄內(nèi)容顏色樣式的方法:

在代碼中設(shè)置狀態(tài)欄內(nèi)容顏色:info.plist文件中直接設(shè)置狀態(tài)欄內(nèi)容顏色:在info.plist中添加字段View controller-based status bar appearance, 當(dāng)其取值為YES時,表示以UIController對狀態(tài)欄的設(shè)置為準(zhǔn),UIApplication對狀態(tài)欄進(jìn)行的設(shè)置將不起作用。

// 在controller中重寫該方法,并返回相應(yīng)值
- (UIStatusBarStyle)preferredStatusBarStyle {
 
 return UIStatusBarStyleLightContent;
}

// 注意:
// 當(dāng)controller嵌入UINavigationController中時,controller中的方法preferredStatusBarStyle是不會自動被調(diào)用的,而navController中的該方法會被調(diào)用;
// 當(dāng)有navController時,在重寫controller中的preferredStatusBarStyle方法同時,我們還應(yīng)重寫navController中的childViewControllerForStatusBarStyle方法。
- (UIViewController *)childViewControllerForStatusBarStyle {
 
 return self.topViewController;
}

當(dāng)字段View controller-based status bar appearance取值為NO時,則以UIApplication為準(zhǔn),控制器設(shè)置狀態(tài)欄的方法preferredStatusBarStyle則根本不會被調(diào)用。

// 狀態(tài)欄內(nèi)容-黑色
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
// 狀態(tài)欄內(nèi)容-白色
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

在info.plist文件中直接設(shè)置狀態(tài)欄內(nèi)容顏色:字段View controller-based status bar appearance取值為NO,且Status bar style取值為UIStatusBarStyleLightContent(可選),則不寫代碼,也可控制應(yīng)用中的狀態(tài)欄內(nèi)容顏色。

2. 隱藏狀態(tài)欄

整個項(xiàng)目隱藏在Targets -> General -> 勾選 Hide status bar 即可。

在單個界面中隱藏

// iOS 9.0 之前
// 隱藏=YES,顯示=NO; Animation:動畫效果
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

// iOS 9.0 之后推薦使用這個
// 注意:該方法可以通過UIController中的方法setNeedsStatusBarAppearanceUpdate來間接調(diào)用
- (BOOL)prefersStatusBarHidden {
 
 return YES;
}

注意:上面兩個操作狀態(tài)方法依然受到Info.plist中字段View controller-based status bar appearance取值得影響,該字段取值為YES時,進(jìn)入controller會自動調(diào)用prefersStatusBarHidden方法。當(dāng)controller嵌入UINavigationController中時,controller中的方法prefersStatusBarHidden是不會自動被調(diào)用的,而navController中的該方法會被調(diào)用;當(dāng)有navController時,在重寫controller中的prefersStatusBarHidden方法同時,我們還應(yīng)重寫navController中的childViewControllerForStatusBarHidden方法。

- (UIViewController *)childViewControllerForStatusBarHidden {
 
 return self.topViewController;
}

啟動頁隱藏狀態(tài)欄,進(jìn)入程序后正常顯示狀態(tài)欄
首先,在Targets->General->勾選中Hide status bar或者在info.plist里面 Status bar is initially hidden 設(shè)置為 YES;
其次,在AppDelegate.m中添加代碼

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}

3. 導(dǎo)航欄


UINavigationController的視圖層次結(jié)構(gòu)比較清晰,用戶可見的導(dǎo)航欄即為其中的***UINavigationBar***,通過它,我們就可以修改導(dǎo)航欄的樣式。下面我們就逐步介紹一些常用的關(guān)于導(dǎo)航欄的操作。

導(dǎo)航欄常用操作

// 隱藏導(dǎo)航欄
//[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];

// 設(shè)置導(dǎo)航背景為紅色
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];

// 設(shè)置navigationBar的透明效果
[self.navigationController.navigationBar setTranslucent:YES]; 
//設(shè)置導(dǎo)航欄的背景圖片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"imgName"] forBarMetrics:UIBarMetricsDefault];

// Attributes 屬性
NSDictionary *textAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:30]};
// 設(shè)置導(dǎo)航欄標(biāo)題的字體大小、顏色
[self.navigationController.navigationBar setTitleTextAttributes:textAttributes];

4. 導(dǎo)航欄常用樣式

在日常開發(fā)中,我們經(jīng)常需要修改導(dǎo)航欄樣式,如使導(dǎo)航欄透明、導(dǎo)航欄尺寸等,在不同樣式導(dǎo)航欄之間的切換時還要注意是否平順...(隱藏,與正常導(dǎo)航欄的切換)

導(dǎo)航欄大標(biāo)題

if (@available(iOS 11.0, *)) {
  [self.navigationController.navigationBar setPrefersLargeTitles:YES];
}

自定義導(dǎo)航欄大標(biāo)題樣式

重寫UINavigationBar中的layoutSubviews方法,可通過發(fā)送通知的形式來監(jiān)聽導(dǎo)航欄高度變化,如下:

-(void)layoutSubviews {
 [super layoutSubviews];
 
 [[NSNotificationCenter defaultCenter] postNotificationName:KEY_UINavigationBar_Height_Changed object:self userInfo:nil];
}

使導(dǎo)航欄透明

當(dāng)需要設(shè)置導(dǎo)航欄透明且title等項(xiàng)正常顯示時,最好將設(shè)置過程置于viewWillAppear:方法中:

//// 需要導(dǎo)航欄透明的ViewController中
- (void)viewWillAppear:(BOOL)animated {
 
 [super viewWillAppear:animated];
 
 _navView.hidden = NO;
 self.edgesForExtendedLayout = UIRectEdgeTop;
 self.navigationController.navigationBar.translucent = YES;
 [self.navigationController.navigationBar setShadowImage:[UIImage new]];
 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
 [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}

//// 導(dǎo)航欄為非透明的ViewController中
- (void)viewWillAppear:(BOOL)animated {
 
 [super viewWillAppear:animated];
 
 self.edgesForExtendedLayout = UIRectEdgeNone;
 self.navigationController.navigationBar.translucent = NO;
 [self.navigationController.navigationBar setShadowImage:nil];
 [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
 [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
 [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];
}

關(guān)于自定義導(dǎo)航欄、tabBar的例子將在后續(xù)文章中介紹...

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。

相關(guān)文章

  • iOS多級列表實(shí)現(xiàn)代碼

    iOS多級列表實(shí)現(xiàn)代碼

    這篇文章主要為大家詳細(xì)介紹了iOS多級列表實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 詳解iOS集成融云SDK即時通訊整理

    詳解iOS集成融云SDK即時通訊整理

    這篇文章主要介紹了詳解iOS集成融云SDK即時通訊整理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • iOS實(shí)現(xiàn)容器視圖控制器的方法

    iOS實(shí)現(xiàn)容器視圖控制器的方法

    本篇文章給大家詳細(xì)講述了iOS實(shí)現(xiàn)容器視圖控制器的方法,對此感興趣的朋友可以測試學(xué)習(xí)下。
    2018-02-02
  • iOS如何定義名為任意的變量詳解

    iOS如何定義名為任意的變量詳解

    這篇文章主要給大家介紹了關(guān)于iOS如何定義名為任意的變量的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-05-05
  • IOS開發(fā)UIButton(左邊圖片右邊文字效果)

    IOS開發(fā)UIButton(左邊圖片右邊文字效果)

    本篇文章主要實(shí)現(xiàn)了實(shí)現(xiàn)UIButton左邊圖片,圖片后面緊跟文字效果,類似微信發(fā)現(xiàn)功能,有需要的朋友可以了解一下。
    2016-10-10
  • iOS移動端軟鍵盤彈起空白和滾動穿透問題解決方案

    iOS移動端軟鍵盤彈起空白和滾動穿透問題解決方案

    這篇文章主要為大家介紹了iOS移動端軟鍵盤彈起空白和滾動穿透問題解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • ios版微信小程序跳一跳輔助

    ios版微信小程序跳一跳輔助

    這篇文章主要為大家詳細(xì)介紹了ios版微信小程序跳一跳輔助,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • iOS中的實(shí)時遠(yuǎn)程配置全紀(jì)錄

    iOS中的實(shí)時遠(yuǎn)程配置全紀(jì)錄

    這篇文章主要給大家介紹了關(guān)于iOS中實(shí)時遠(yuǎn)程配置的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • iOS  隱藏導(dǎo)航條和狀態(tài)欄實(shí)現(xiàn)方法

    iOS 隱藏導(dǎo)航條和狀態(tài)欄實(shí)現(xiàn)方法

    這篇文章主要介紹了 iOS隱藏導(dǎo)航條和狀態(tài)欄實(shí)現(xiàn)方法的相關(guān)資料,有時候根據(jù)需求開發(fā)APP 需要隱藏導(dǎo)航欄和狀態(tài)欄,這里提供了實(shí)現(xiàn)方法需要的朋友可以參考下
    2016-11-11
  • iOS實(shí)時監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變

    iOS實(shí)時監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)時監(jiān)控網(wǎng)絡(luò)狀態(tài)的改變的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-08-08

最新評論

中西区| 诸暨市| 屏东市| 常熟市| 广宁县| 丹棱县| 邓州市| 微山县| 蓬莱市| 兴安盟| 南岸区| 临桂县| 齐河县| 太康县| 轮台县| 静安区| 高碑店市| 竹北市| 蓝田县| 莆田市| 科技| 永胜县| 通州市| 广宗县| 临海市| 都江堰市| 阿瓦提县| 东台市| 翼城县| 仙桃市| 百色市| 衡南县| 宁德市| 马山县| 西华县| 安康市| 阿克陶县| 汨罗市| 彰化市| 涡阳县| 蓬莱市|