改变导航栏背景颜色 (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