038 changing the color of the status bar (extended knowledge: Message notification knowledge about different versions of iOS)

Source: Internet
Author: User

The effect is as follows:

ViewController.h

1 #import <UIKit/UIKit.h>23@interface  viewcontroller: Uiviewcontroller4@end

Viewcontroller.m

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4- (void) Usernotificationdidpush: (UIApplication *) Application;5 @end6 7 @implementationViewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload];  One  AUILabel *lblmessage = [[UILabel alloc] Initwithframe:cgrectinset (Self.view.bounds, -, -)]; -Lblmessage.autoresizingmask = Uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibleheight; -Lblmessage.text =@"need to add line view controller-based status bar appearance=no in PL file; Toggle status bar color after touch screen"; theLblmessage.numberoflines =0; -Lblmessage.textalignment =Nstextalignmentcenter; -Lblmessage.textcolor =[Uicolor Browncolor]; -Lblmessage.backgroundcolor =[Uicolor Whitecolor]; + [Self.view Addsubview:lblmessage];  -  +Self.navigationItem.prompt =@"look at the color change in the status bar"; ASelf.navigationItem.title =@"change the color of the status bar"; at } -  -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; -     //Dispose of any resources the can be recreated. - } in  -- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event { toUIApplication *application =[UIApplication sharedapplication]; +     //status bar style toggle -     if(Application.statusbarstyle = =Uistatusbarstyledefault) { theApplication.statusbarstyle =uistatusbarstylelightcontent; *}Else { $Application.statusbarstyle =Uistatusbarstyledefault;Panax Notoginseng     }    -  the [self usernotificationdidpush:application]; + } A  the /** + * Extended Knowledge: Message notification knowledge about different versions of iOS -  * $ * @param application shared uiapplication Singleton mode object instance $  */ -- (void) Usernotificationdidpush: (UIApplication *) Application { -     //number of application icon markers the     //because the Registerusernotificationsettings method is a iOS8 method, it cannot be used in the following versions of IOS8; -     if([[[[Uidevice Currentdevice] systemversion] Floatvalue] >=8.0) {WuyiUiusernotificationsettings *settings =[uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge categories:nil]; the [Application registerusernotificationsettings:settings]; -}Else { Wu [Application registerforremotenotifications]; -     } AboutApplication.applicationiconbadgenumber =3;//number of Message tokens for the application icon $     //Self.tabBarItem.badgeValue = @ "3";//number of message markers on the bottom tab -  -     /*determine if push push notifications are open; same as above. Separate processing required - uiremotenotificationtype types; A if ([[[[ Uidevice Currentdevice] systemversion] floatvalue] >= 8.0) { + types = [[UIApplication sharedapplication] currentusernotificationsettings].types; the } else { - types = [[UIApplication sharedapplication] enabledremotenotificationtypes]; $      } the BOOL isenablednotification = types & Uiremotenotificationtypealert; the     */ the } the  - @end

AppDelegate.h

1 #import <UIKit/UIKit.h>23@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 @interfaceappdelegate ()5 @end6 7 @implementationappdelegate8 9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Ten_window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; OneViewcontroller *viewcontroller =[[Viewcontroller alloc] init]; A_navigationcontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; -_window.rootviewcontroller =_navigationcontroller; - [_window Addsubview:_navigationcontroller.view]; the [_window makekeyandvisible]; -     returnYES; - } -  +- (void) Applicationwillresignactive: (UIApplication *) Application { - } +  A- (void) Applicationdidenterbackground: (UIApplication *) Application { at } -  -- (void) Applicationwillenterforeground: (UIApplication *) Application { - } -  -- (void) Applicationdidbecomeactive: (UIApplication *) Application { in } -  to- (void) Applicationwillterminate: (UIApplication *) Application { + } -  the @end

038 changing the color of the status bar (extended knowledge: Message notification knowledge about different versions of iOS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.