- Basis
-
UI (User interface) is the interface; iOS apps are made up of a variety of UI controls
-
UIWindow is a window, learning the first basic class, is a container, you can put different content on the container, each app needs to use window to show the content to the user
-
UIView is a view that represents a rectangular area on the screen
-
UIView and UIWindow In addition to inheritance there is no other relationship, window is the windows, above the UIView, usually invisible UIWindow, we use the self is the system built UIView
-
Generally do not directly add the view on the UIWindow directly
-
Create a view: 1, open up space and initialize the view (given position and size) 2, make some settings on the view (such as background color) 3, add views to the window to display [Self.window addsubview:blueview]4, Release the View object,
- Create Self.window = [[UIWindow alloc] initWithFrame: [uiscreen mainscreen].bounds];//Create window to fill the screen. [Self.window makekeyandvisible];//makes it the main window and visually
- Self.window.backgroundColor = [uicolor whitecolor];//setting background color
- Self.window.rootViewController = [[Viewcontroller alloc] init];//set root view controller, to add header file
- Process:main->app->view->
- * Add sub-view *
- Self.view.backgroundColor = [Uicolor Redcolor];
- UIView *view = [[UIView alloc] init];
- View.frame = CGRectMake (10, 20, 30, 40);//relative to the position of the parent view, pay attention to the rationality of coordinates and dimensions, and ensure that the coordinates and dimensions do not exceed the top-level.
- view.userinteractionenabled = no;//Whether the user is allowed to click, if set to No, the child view does not overwrite the parent view of the Click event
- self.view.userInteractionEnabled = no;//If the parent view does not allow interaction, child view events are also masked.
- View.backgroundcolor = [Uicolor Whitecolor];
- [Self.view addsubview:view];//adds a later view to the previous view
- View.tag = 1;//Set View label
- UIView *VIEW3 = [Self.view viewwithtag:1];//Gets the view with the label one in the parent view.
- View.alpha = 0;//Sets the transparency of the view, 0~1 floating point
- Self.view.alpha = 0;//If the parent view is transparent, the child view will not be visible
- View.hidden = yes;//Sets whether the view is hidden
- Self.view.hidden = yes;//If the parent view is hidden, the child view is also hidden
- Operation
-
Nsarray*subviews = [Redview subviews];//get all the child views of this view
-
Uiview*superview = [Redview superview];//Gets the parent view of this view
-
[View removefromsuperview];//Remove
-
[Self.view Insertsubview:view atindex:1];//adds a child view to a location in the parent view
-
[Self.view insertsubview:view2 abovesubview:view];//adds view1 to the parent view and above the view
-
[Self.view insertsubview:view2 belowsubview:view];//adds view1 to the parent view and is under view.
-
[Self.view exchangesubviewatindex:0 withsubviewatindex:1];//Swap two-position view
-
[Self.view bringsubviewtofront:view];//moves a child view to the front of the parent view
-
[Self.view sendsubviewtoback:view2];//moves a child view to the bottom of the parent view
-
Clicked Method-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{
-
NSLog (@ "clicked");
-
}
Ios--uiview and UIWindow usage