IOS开发-设置导航栏和状态栏的状态和显示指定高度的控制器

改变导航栏背景颜色 (1)

self.navigationController.navigationBar.barTintColor = [UIColor redColor];

(2) 默认为白色

 self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

改变导航栏字体颜色

// 第一种
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

// 第二种
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

改变导航栏字体大小

 [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:25]}];

获取状态栏的高度

CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];

改变状态栏的颜色(方法1)

UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusRect.size.height, self.view.bounds.size.width, statusRect.size.height)];
statusBarView.backgroundColor = [UIColor greenColor];
[self.navigationController.navigationBar addSubview:statusBarView];

显示指定高度的控制器

//
//  HalfScreenViewController.m
//  SDWebImageDemo
//

//

#import "HalfScreenViewController.h"

@interface HalfScreenViewController ()
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic, strong) UIWindow *testWindow;
@property (nonatomic, strong) UIViewController *vc;
@property (nonatomic, strong) UIButton *button;
@end

@implementation HalfScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // NSString *string = NSStringFromCGRect(self.navigationController.navigationBar.frame);
    
    //self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    [self.view addSubview:self.button];
    self.view.backgroundColor = [UIColor whiteColor];
    self.vc = [[UIViewController alloc] init];
    [self.view addSubview:self.testWindow];
    self.testWindow.rootViewController = self.vc;
}

- (UIWindow *)testWindow {
    if (!_testWindow) {
        _testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2)];
        _testWindow.windowLevel = UIWindowLevelAlert;
        _testWindow.backgroundColor = UIColor.blackColor;
        _testWindow.alpha = 0.5;
        [_testWindow setClipsToBounds:YES];
        _testWindow.layer.cornerRadius = 10;
        _testWindow.hidden = YES;
    }
    return _testWindow;
}
- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        _button.frame = CGRectMake(100, 400, 100, 100);
        _button.backgroundColor = [UIColor redColor];
        [_button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

- (void)clickButton {
    self.testWindow.hidden = NO;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:1.0 animations:^{
        weakSelf.testWindow.hidden = YES;
    }];
}

@end

显示指定高度的导航控制器

//
//  HalfScreenViewController.m
//  SDWebImageDemo
//

//

#import "HalfScreenViewController.h"

@interface HalfScreenViewController ()
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic, strong) UIWindow *testWindow;
@property (nonatomic, strong) UIViewController *vc;
@property (nonatomic, strong) UIButton *button;
@end

@implementation HalfScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.button];
    self.view.backgroundColor = [UIColor whiteColor];
    self.vc = [[UIViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.vc];
    nav.navigationBar.barTintColor = UIColor.blackColor;
    nav.navigationBar.alpha = 0.6;
    [self.view addSubview:self.testWindow];
    self.testWindow.rootViewController = nav;
}

- (UIWindow *)testWindow {
    if (!_testWindow) {
        _testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2)];
        _testWindow.windowLevel = UIWindowLevelAlert;
        _testWindow.backgroundColor = UIColor.blackColor;
        _testWindow.alpha = 0.5;
        [_testWindow setClipsToBounds:YES];
        _testWindow.layer.cornerRadius = 10;
        _testWindow.hidden = YES;
    }
    return _testWindow;
}
- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        _button.frame = CGRectMake(100, 400, 100, 100);
        _button.backgroundColor = [UIColor redColor];
        [_button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

- (void)clickButton {
    self.testWindow.hidden = NO;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:1.0 animations:^{
        weakSelf.testWindow.hidden = YES;
    }];
}

@end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值