欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-20 20:32:58
ios点击按钮隐藏状态栏详解 前言: 最近学习ios的基础知识,实现隐藏状态栏的功能,这里就记录下来,希望对大家有所帮助 实例代码: @interface...

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

前言:

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

实例代码:

@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;
}

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

上一篇:

下一篇: