IOS development UI-program startup principle and UIApplication

Source: Internet
Author: User

IOS development UI-program startup principle and UIApplication
I. UIApplication
1. Brief Introduction
(1) A UIApplication object represents an application. A UIApplication object represents an application.


(2) Each application has its own UIApplication object, which is a singleton. If you try to create a new UIApplication object in the program, an error is reported.


(3) The singleton object can be obtained through [UIApplicationsharedApplication ].


(4) The first object created after an iOS program is started is the UIApplication object, and there is only one (get two UIApplication objects through code, and print the address to see that the address is the same ).


(5) use the UIApplication object to perform some application-level operations


2. Application-level operation example:


1) set the red alarm number in the upper-right corner of the application icon (for example, when a QQ message is sent, the icon displays 1, 2, and 3 new messages .)


@ Property (nonatomic) NSInteger applicationIconBadgeNumber;

-(Void) viewDidLoad
{
[Super viewDidLoad];
// Create and add a button
UIButton * btn = [[UIButton alloc] initWithFrame: CGRectMake (100,100, 60, 30)];
[Btn setTitle: @ "button" forState: UIControlStateNormal];
[Btn setBackgroundColor: [UIColor brownColor];
[Btn addTarget: self action: @ selector (onClick) forControlEvents: UIControlEventTouchUpInside];
[Self. view addSubview: btn];
}
-(Void) onClick
{
NSLog (@ "Click Event ");
// Error. Only one unique UIApplication object can be created.
// UIApplication * app = [[UIApplication alloc] init];

// Obtain the UIApplication object of the program through sharedApplication
UIApplication * app = [UIApplication sharedApplication];
App. applicationIconBadgeNumber = 123;
}

 

2) set the visibility of the network indicator


@ Property (nonatomic, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;


Code and effects:


// Sets the online animation of the indicator.
App. networkActivityIndicatorVisible = YES;

 

3) Manage the status bar


From iOS 7, the system provides two methods to manage the status bar.


A. Manage through UIViewController (each UIViewController can have its own different status bar ).


In iOS7, the status bar is managed by UIViewController by default. The following methods can be implemented by UIViewController to easily manage the visibility and style of the status bar.


Style of the status bar-(UIStatusBarStyle) preferredStatusBarStyle;


Status Bar visibility-(BOOL) prefersStatusBarHidden;

 

# Pragma mark-set the style of the status bar
-(UIStatusBarStyle) preferredStatusBarStyle
{
// Set it to white
// Return UIStatusBarStyleLightContent;
// Black by default
Return UIStatusBarStyleDefault;
}
# Pragma mark-set whether the status bar is hidden (NO)
-(BOOL) prefersStatusBarHidden
{
Return NO;
}

Related Article

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.