首页 技术 正文
技术 2022年11月23日
0 收藏 950 点赞 4,076 浏览 2375 个字
  1. [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //显示
  2. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //隐藏

让状态栏显示网络等待标志

状态栏是可以通过UIApplication类提供的一些方法来修改的,比如完全去掉状态栏或者修改风格,不过这些改变只是在你的程序内部,当你退出你的程序又会复原。

  1. UIApplication *myApp = [UIapplication sharedApplication];

1.隐藏状态栏

  1. [myApp setStatusBarHidden:YES animated:YES];

复制代码

记得隐藏状态栏后的你的“桌面”就增加320×20的大小,所以最好是在任何window或者view创建之前隐藏它。

2.状态栏风格

  1. [myApp setStatusBarStyle: UIStatusbarStyleBlackOpaque];
  1. typedef enum {
  2. UIStatusBarStyleDefault,
  3. UIStatusBarStyleBlackTranslucent,
  4. UIStatusBarStyleBlackOpaque
  5. } UIStatusBarStyle;

3.状态栏方向

  1. [myApp setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
  1. typedef enum {
  2. UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
  3. //竖屏,垂直向上
  4. UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
  5. //竖屏,垂直方向上下颠倒
  6. UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
  7. //设备逆时针旋转到横屏模式
  8. UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
  9. //设备顺时针旋转到横屏模式
  10. } UIInterfaceOrientation;

有时候,需要在状态栏上显示一些自定义信息,比如新浪微博的官方iOS客户端:告知用户信息处于发送队列、发送成功或者发送失败。

ios状态栏的一些操作

如上图,通过在状态栏显示自定义信息,可以给用户友好又不影响软件使用的提示。

为此,我们显得定义一个自定义状态栏类,包含一个显示信息的Label:

  1. @interface CustomStatusBar : UIWindow
  2. {
  3. UILabel *_messageLabel;
  4. }
  5. – (void)showStatusMessage:(NSString *)message;
  6. – (void)hide;
  7. @end

接着,设置大小和系统状态栏一致,背景为黑色:

  1. self.frame = [UIApplication sharedApplication].statusBarFrame;
  2. self.backgroundColor = [UIColor blackColor];

到这里,为了让自定义的状态栏可以让用户看到,还需要设置它的windowLevel。

在iOS中,windowLevel属性决定了UIWindow的显示层次。默认的windowLevel为UIWindowLevelNormal,即0.0。

系统定义了三个层次如下,具体可参考官方文档

  1. const UIWindowLevel UIWindowLevelNormal;
  2. const UIWindowLevel UIWindowLevelAlert;
  3. const UIWindowLevel UIWindowLevelStatusBar;
  4. typedef CGFloat UIWindowLevel;

为了能够覆盖系统默认的状态栏,我们把自定义的状态栏的windowLevel调高点:

  1. self.windowLevel = UIWindowLevelStatusBar + 1.0f;

最后,为显示信息和隐藏添加一点无伤大雅的动画:

  1. – (void)showStatusMessage:(NSString *)message
  2. {
  3. self.hidden = NO;
  4. self.alpha = 1.0f;
  5. _messageLabel.text = @””;
  6. CGSize totalSize = self.frame.size;
  7. self.frame = (CGRect){ self.frame.origin, 0, totalSize.height };
  8. [UIView animateWithDuration:0.5f animations:^{
  9. self.frame = (CGRect){ self.frame.origin, totalSize };
  10. } completion:^(BOOL finished){
  11. _messageLabel.text = message;
  12. }];
  13. }
  14. – (void)hide
  15. {
  16. self.alpha = 1.0f;
  17. [UIView animateWithDuration:0.5f animations:^{
  18. self.alpha = 0.0f;
  19. } completion:^(BOOL finished){
  20. _messageLabel.text = @””;
  21. self.hidden = YES;
  22. }];;
  23. }

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,987
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,503
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,347
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,130
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,842