038改变状态栏的颜色(扩展知识:关于iOS不同版本的消息通知知识)

效果如下:

ViewController.h

1 #import <UIKit/UIKit.h>
2
3 @interface ViewController : UIViewController
4 @end

ViewController.m

 1 #import "ViewController.h"
 2
 3 @interface ViewController ()
 4 - (void)userNotificationDidPush:(UIApplication *)application;
 5 @end
 6
 7 @implementation ViewController
 8
 9 - (void)viewDidLoad {
10     [super viewDidLoad];
11
12     UILabel *lblMessage = [[UILabel alloc] initWithFrame:CGRectInset(self.view.bounds, 20, 20)];
13     lblMessage.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
14     lblMessage.text = @"需要在PL文件新增行View controller-based status bar appearance=NO;触摸画面后,切换状态条颜色";
15     lblMessage.numberOfLines = 0;
16     lblMessage.textAlignment = NSTextAlignmentCenter;
17     lblMessage.textColor = [UIColor brownColor];
18     lblMessage.backgroundColor = [UIColor whiteColor];
19     [self.view addSubview:lblMessage];
20
21     self.navigationItem.prompt = @"看看状态栏的颜色变化";
22     self.navigationItem.title = @"改变状态栏的颜色";
23 }
24
25 - (void)didReceiveMemoryWarning {
26     [super didReceiveMemoryWarning];
27     // Dispose of any resources that can be recreated.
28 }
29
30 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
31     UIApplication *application = [UIApplication sharedApplication];
32     //状态栏样式切换
33     if (application.statusBarStyle == UIStatusBarStyleDefault) {
34         application.statusBarStyle = UIStatusBarStyleLightContent;
35     } else {
36         application.statusBarStyle = UIStatusBarStyleDefault;
37     }
38
39     [self userNotificationDidPush:application];
40 }
41
42 /**
43  *  扩展知识:关于iOS不同版本的消息通知知识
44  *
45  *  @param application 共享的UIApplication单例模式对象实例
46  */
47 - (void)userNotificationDidPush:(UIApplication *)application {
48     //应用程序图标标记数
49     //因为registerUserNotificationSettings方法为iOS8的方法,无法在iOS8以下版本使用;所以需要分别处理
50     if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
51         UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
52         [application registerUserNotificationSettings:settings];
53     } else {
54         [application registerForRemoteNotifications];
55     }
56     application.applicationIconBadgeNumber = 3; //应用程序图标的消息标记数
57     //self.tabBarItem.badgeValue = @"3"; //底部选项卡的消息标记数
58
59     /* 判断Push推送通知是否打开;同上面一样道理需要分别处理
60      UIRemoteNotificationType types;
61      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
62      types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
63      } else {
64      types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
65      }
66      BOOL isEnabledNotification = types & UIRemoteNotificationTypeAlert;
67     */
68 }
69
70 @end

AppDelegate.h

1 #import <UIKit/UIKit.h>
2
3 @interface AppDelegate : UIResponder <UIApplicationDelegate>
4 @property (strong, nonatomic) UIWindow *window;
5 @property (strong, nonatomic) UINavigationController *navigationController;
6
7 @end

AppDelegate.m

 1 #import "AppDelegate.h"
 2 #import "ViewController.h"
 3
 4 @interface AppDelegate ()
 5 @end
 6
 7 @implementation AppDelegate
 8
 9 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
10     _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
11     ViewController *viewController = [[ViewController alloc] init];
12     _navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
13     _window.rootViewController = _navigationController;
14     [_window addSubview:_navigationController.view];
15     [_window makeKeyAndVisible];
16     return YES;
17 }
18
19 - (void)applicationWillResignActive:(UIApplication *)application {
20 }
21
22 - (void)applicationDidEnterBackground:(UIApplication *)application {
23 }
24
25 - (void)applicationWillEnterForeground:(UIApplication *)application {
26 }
27
28 - (void)applicationDidBecomeActive:(UIApplication *)application {
29 }
30
31 - (void)applicationWillTerminate:(UIApplication *)application {
32 }
33
34 @end
时间: 2024-12-29 17:09:02

038改变状态栏的颜色(扩展知识:关于iOS不同版本的消息通知知识)的相关文章

Android学习第八弹之改变状态栏的颜色使其与APP风格一体化

公众号:smart_android 作者:耿广龙|loonggg 点击"阅读原文",可查看更多内容和干货 导语:沉浸式状态栏,改变状态栏的颜色使之与APP风格一体化是不是感觉很漂亮,很美?其实实现这种效果并不难,google在4.4及以下提供了相关的方法. 我相信大家肯定看到过很多软件有沉浸式状态栏,在运行该App时改变了手机屏幕顶部状态栏的颜色,使他们的风格非常的统一,看起来异常的漂亮和清爽.想不想实现这种效果呢,其实在Android KITKAT上有一个新的特性可以设置手机状态栏的

改变状态栏的颜色

改变颜色要在viewwillApper中开始改变,如果是在 3.在个别状态栏字体颜色不一样的vc中 -(void)viewWillAppear:(BOOL)animated{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [UIApp

Android设置沉浸式状态栏时改变状态栏的颜色(只对MIUI V6可用)

Android支持在API 19及以上使用沉浸式状态,但在MIUI V6下如果扩展的颜色比较浅,会导致状态栏的文字无法看清. 在Android4.4设备上支持沉浸式状态栏,只需要添加values-v19/styles.xml 下添加 <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> <item name="android:window

把所有界面的状态栏字体颜色设置为白色--iOS开发系列---项目中成长的知识一

第一步: 在info.plist中 View controller-based status bar appearance这个属性设置为 View controller-based status bar appearance =NO 这个意思是:View Controller 不对status Bar 显示进行操作 第二步: 由于项目是一个以tabbarController的父类进行开发的;所以在这个父类里面添加如下方法: [[UIApplication sharedApplication] s

改变状态栏颜色

要改变状态栏颜色的前提条件这个是让颜色显示 info.plist中 View controller-based status bar appearance这个属性 View controller-based status bar appearance =NO 统一设置(但是只有三中系统的)在plist里增加一行 UIStatusBarStyle(或者是“Status bar style”也可以) 单独设置  白色[UIApplication sharedApplication].statusBa

[iOS]改变状态栏颜色

改变状态栏颜色为白字黑底: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false) } 另外要在info里面

如何改变macOS顶部状态栏的颜色?

今天要说的是一个很基础的系统自带的功能.它可以使你的顶部菜单栏和Dock栏变成黑色透明状态,也就是暗色菜单栏. 系统偏好设置 - 通用,如图: 选择「深色模式」,如图: 高亮显示颜色,改完之后是红色,如图: 以上就是[Mac小技巧]如何改变顶部状态栏的颜色的全部内容啦,您学会了吗?更多Mac软件 https://www.macdown.com 欢迎您的访问. 原文地址:https://www.cnblogs.com/macw/p/12170666.html

关于在ios7之后改变状态栏颜色

看到网上都说 在ios7之后要这样设置 首先,需要在Info.plist配置文件中,增加键:UIViewControllerBasedStatusBarAppearance,并设置为YES: 然后,在UIViewController子类中实现以下两个方法: - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } - (BOOL)prefersStatusBarHidden { ret

IOS总结_IOS7.0以后改变状态栏字体颜的问题

首先info.plist文件中,加入View controller-based status bar appearance项 如果设为YES,则View controller对status bar的设置优先级高于application的设置:设置为NO则以application的设置为准. 虽然7.0SDK后在UIViewController中也加入加入了 - (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); //