国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 自定義狀態欄和導航欄詳細介紹

2020-07-26 03:04:45
字體:
來源:轉載
供稿:網友

iOS 自定義狀態欄和導航欄

           開發IOS APP 經常會根據需求更改狀態欄和導航欄,這里整理了幾種方法,大家可以看下。

導航欄透明

-(void)viewWillAppear:(BOOL)animated { //viewWillAppear中設置透明 [super viewWillAppear:animated]; [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; //用空圖片填充機位透明 [self.navigationBar setShadowImage:[UIImage new]];//naviBar底部的seperatorLine}-(void)viewDidDisappear:(BOOL)animated { //viewWillAppear中設置恢復 [super viewDidDisappear:animated]; [self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [self.navigationBar setShadowImage:shadowImage];}

導航欄漸變

barImageView = self.navigationController.navigationBar.subviews.firstObject;-(void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat minAlphaOffset = - 64; CGFloat maxAlphaOffset = 200;  CGFloat offset = scrollView.contentOffset.y;  CGFloat alpha = (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset); _barImageView.alpha = alpha;}

狀態欄字體顏色改變

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;//黑色[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;//白色

導航欄隱藏

如果導航欄自定義度高,需要完全自己重寫,可以隱藏原來的導航欄,并定義一個新的view

-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBarHidden = YES;}-(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; self.navigationController.navigationBarHidden = NO;}-(void)ys_initNavigationBar { self.navigationController.interactivePopGestureRecognizer.delegate = (id)self; // 保留右滑pop的手勢 _naviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 64)]; _naviBar.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_naviBar];UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, _naviBar.height-0.5, self.view.width, 0.5)];line.backgroundColor = [UIColor colorForHex:@"f0f0f0"];[_naviBar addSubview:line];// 返回backButton = [UIButton buttonWithType:UIButtonTypeCustom];backButton.frame = CGRectMake(0, 20, 44, 44);[backButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:backButton];// 標題naviLable = [[UIButton alloc] initWithFrame:CGRectMake(44, 20, self.view.width-44*2, 44)];naviLable.backgroundColor = [UIColor clearColor];naviLable.font = [UIFont systemFontOfSize:16];naviLabel.textAlignment = NSTextAlignmentCenter;[self.view addSubview: naviLable];}-(void)scrollViewDidScroll:(UIScrollView *)scrollView { //navigationBar change CGFloat minAlphaOffset = 0; CGFloat maxAlphaOffset = 40; CGFloat offset = scrollView.contentOffset.y; CGFloat alpha = (offset - minAlphaOffset) / (maxAlphaOffset - minAlphaOffset); _naviBar.alpha = alpha; naviLabel.alpha = alpha;}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 锦州市| 紫金县| 西充县| 茂名市| 东乌珠穆沁旗| 商河县| 贵南县| 宝丰县| 平罗县| 北安市| 广德县| 枣阳市| 确山县| 荆州市| 岚皋县| 巢湖市| 宜兰县| 邵阳市| 清涧县| 五常市| 赣州市| 革吉县| 衡水市| 苍南县| 巧家县| 拜城县| 容城县| 沙坪坝区| 同心县| 宜昌市| 牙克石市| 平乡县| 贡觉县| 郯城县| 张家川| 肥西县| 综艺| 大兴区| 景洪市| 镇安县| 兴宁市|