[OcUI diary] UIwindow and UIview, ocuiuiwindow

Source: Internet
Author: User

[OcUI diary] UIwindow and UIview, ocuiuiwindow

In the current version of xcode, xcode has already created the main window and main view for us, but this is not a good thing for beginners.

Next, I will introduce how to create a window and set the main view.

1. Delete the selected files first.

2. Delete the main in Step 4 according to the label in.

3. We enter AppDelegate. m

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions method override

1 // create a window and initialize it. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; 3 // set this window as the main window and display it in Step 4 [self. window makeKeyAndVisible]; 5 // create an initialized View Controller in step 3 (import the header file) 6 ViewController * viewcontroller = [[ViewController alloc] init]; 7 // Step 4: Set the window and View Controller 8 self. window. rootViewController = viewcontroller;

Here, we run the simulator and find that nothing is completely black.

This is because the background color of the default view is clearcolor (clearcolor is different from transparency: clearcolor does exist, but it is invisible, just like half of the glass)

Therefore, we need to set the background color for the view. At this time, the simulator will have a visible interface.

 

 

Next, we will explain the UIView.

1 // set the background color for the main view. 2 self. view. backgroundColor = [UIColor whiteColor]; 3 4 // to create a view and display it, perform the following four steps 5 // 1. create view 6 UIView * view1 = [[UIView alloc] init]; 7 // 2. set the frame of the view (using the CGRectMake method, the first two numbers are the horizontal and vertical distances from the origin (the upper left corner). The last two numbers are the length and width of the view 8 view1.frame = CGRectMake (10, (10,200,200); 9 // 3. set the background color of the view to 10 view1.backgroundColor = [UIColor blackColor]; 11 // 4. add view12 [self. view addSubview: view1];

The basic usage of view is described above. The following describes some other common usage.

1 // set the default view tag to 0 2 view1.tag = 1; 3 // whether to respond to interaction (touch) The default value is no 4 view1.userInteractionEnabled = NO; 5 // assign the view marked as 1 in the subview to another view. The original view will change. 6. UIView * view2 = [self. view viewWithTag: 1]; 7 // delete yourself from the parent view 8 [view2 removeFromSuperview]; 9 10 11 12 // Add the insert method 13 // Add a view to the layer at the first time add a view to the layer after layer 0th Add a total of 14 // insert subview 15 [self. view insertSubview: view2 atIndex: 0]; 16 // Add the view1 subview to view2 subview. view2 must be 17 [self. view insertSubview: view1 belowSubview: view2]; 18 // Add the view1 subview to view2 subview. view2 must be 19 [self. view insertSubview: view1 aboveSubview: view2]; 20 21 // setting the transparency between 0 and 1 will affect the sub-view 22 view1.alpha = 0.2; 23 // setting the visibility will affect the subview 24 view1.hidden = YES;

 

 

This is all about today. If you have any questions, please contact me and discuss it. In order to answer your questions as soon as possible.

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.