Common Properties and methods of UIView for iPone Application Development

Source: Internet
Author: User

Common Properties and methods of UIView for iPone Application Development
IPone Application Development UIView common attributes and Methods common attributes alpha view transparency 0.0f-1.0f backgroundColor view background color set of subviews hidden view whether to hide the unique identifier of the tag view, is the parent view of an integer data superview. Is multipleTouchEnabled a common method to enable multi-touch userInteractionEnable to respond to a touch event?

-(Void) removeFromSuperview; // Delete the current view from the parent view-(void) insertSubview :( UIView *) view atIndex :( NSInteger) index; // Insert the view from the specified index location-(void) exchangeSubviewAtIndex :( NSInteger) index1 withSubviewAtIndex :( NSInteger) index2; // switch the view based on the specified view's index location-(void) addSubview :( UIView *) view; // Add a new view on the current view layer. This method Adds 1-(void) insertSubview (UIView *) to the reference of the parameter view *) view belowSubview :( UIView *) siblingSubview; // Add a view under the specified view-(void) insertSubview :( UIView *) view aboveSubVIew :( UIView *) siblingSubview; // Add a view (void) bringSubviewToFront :( UIView *) view on the top of the specified page; // move the view specified by the parameter to the front of the view-(void) sendSubviewToBack :( UIView *) view; // move the view specified by the parameter to the end of the view-(UIView *) viewWithTag :( NSInteger) tag; // obtain an existing UIView object based on the tag attribute
Implementation
Implementation Method: 1. it can be implemented in pure code, mainly by manually writing code. Instead of automatically loading the main view in Xcode, we manage the view manually without using ViewController. 2. you can use the UIView and UIVindow provided by Xcode to implement
Implementation Method

Step 1:
First, delete the ViewController. h, ViewController. m, Main. storyboard, and LaunchScre. xil files in the project, and manually write the loading window and view files.
Step 2:
Delete the Main in the Main interface of the project, and delete the LaunchScreen in the Launch Screen File.
Next, we will write code in the AppDelegate. m file to load the main view and window.

# Import AppDelegate. h @ interface AppDelegate () @ end @ implementation AppDelegate-(BOOL) application :( UIApplication *) application didFinishLaunchingWithOptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. window. backgroundColor = [UIColor grayColor]; UIView * bgView = [[UIView alloc] initWithFrame: self. window. bounds]; bgView. backgroundColor = [UIColor orangeColor]; [self. window addSubview: bgView]; UIView * greenView = [[UIView alloc] initWithFrame: CGRectMake (20, 20,280,160)]; greenView. tag = 100; // This tag is the unique identifier of the view, which is actually an integer greenView. backgroundColor = [UIColor greenColor]; // bgView establishes a relationship with greenView. The parent-child relationship bgView is called the parent view and greenView is called the Child view. // [bgView addSubview: greenView]; greenView. superview. backgroundColor = [UIColor redColor]; UIView * blueView = [[UIView alloc] initWithFrame: CGRectMake (20,190,280,160)]; blueView. tag = 101; blueView. backgroundColor = [UIColor blueColor]; // [bgView addSubview: blueView]; // you can change the background color of the parent view in the Child view. superview. backgroundColor = [UIColor lightGrayColor]; [bgView addSubview: blueView]; [bgView addSubview: greenView]; UIButton * btn = [[UIButton alloc] usage: CGRectMake (20, 20,240, 40)]; [btn setTitle: @ forState: UIControlStateNormal]; [btn setTitleColor: [UIColor blackColor] forState: UIControlStateNormal]; [btn addTarget: self action: @ selector (onButton) forControlEvents: UIControlEventTouchUpInside]; btn. backgroundColor = [UIColor lightGrayColor]; [bgView addSubview: btn]; // greenView. userInteractionEnabled = NO; // [greenView addSubview: btn]; UIView * gView = [bgView viewWithTag: 100]; gView. backgroundColor = [UIColor purpleColor]; UIView * bView = [bgView viewWithTag: 101]; bView. backgroundColor = [UIColor redColor]; [self. window makeKeyAndVisible]; return YES;}-(void) onButton {NSLog (@ % s ,__ func _);} @ end

The running result is as follows:

Result Analysis:
The view here has layers. The bottom layer is the orange view bgView, which is the parent view. The others are subviews. Other views are placed on bgView based on the position and size in the code. the parent view baVIew can change its attributes through the Child view.
  
  

 

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.