服务器之家

服务器之家 > 正文

IOS点击按钮隐藏状态栏详解及实例代码

时间:2021-03-04 13:57     来源/作者:iOS开发网

IOS点击按钮隐藏状态栏详解

前言:

最近学习IOS的基础知识,实现隐藏状态栏的功能,这里就记录下来,希望对大家有所帮助

实例代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@interface SecondViewController ()
@property (nonatomic, assign,getter=isHideStatus) BOOL hideStatus;
@end
 
@implementation SecondViewController
 
- (void)viewDidLoad {
  [super viewDidLoad];
  self.view.backgroundColor = [UIColor whiteColor];
 
  UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
  button.center = self.view.center;
  button.backgroundColor = [UIColor blueColor];
  [button setTitle:@"隐藏导航栏" forState:UIControlStateNormal];
  [button addTarget:self action:@selector(hideFrame) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:button];
 
  self.hideStatus = [UIApplication sharedApplication].statusBarHidden;
 
  // Do any additional setup after loading the view, typically from a nib.
}
 
 
- (void)hideFrame {
 
  [self setNeedsStatusBarAppearanceUpdate];//调用该方法后系统会调用prefersStatusBarHidden方法
  self.hideStatus = !self.hideStatus;
 
}
- (BOOL)prefersStatusBarHidden
{
  return self.hideStatus;
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部