UIView-layer method, uiview-Layer

Source: Internet
Author: User

UIView-layer method, uiview-Layer

//// ViewController. m // UIView-layer concept /// Created by wangtouwang on 15/5/5. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ property (nonatomic, strong) UIView * viewA; @ property (nonatomic, strong) UIView * viewB; @ property (nonatomic, strong) UIView * viewC; @ end @ implementation ViewController @ synthesize viewA; @ synthesize viewB; @ synthesize viewC;-(void) viewDidLoad {[super viewDidLoad]; [self. view setBackgroundColor: [UIColor whiteColor]; [self. navigationItem setTitle: @ "layer concept"]; UIButton * addBtn1 = [[UIButton alloc] initWithFrame: CGRectMake (10, 70, 60, 30)]; [addBtn1 setTitle: @ "add" forState: UIControlStateNormal]; addBtn1.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn1 setBackgroundColor: [UIColor grayColor]; [addBtn1 addTarget: self action: @ selector (addDract) forControlEvents: role]; [self. view addSubview: addBtn1]; UIButton * addBtn2 = [[UIButton alloc] initWithFrame: CGRectMake (80, 70, 60, 30)]; [addBtn2 setTitle: @ "delete" forState: Unknown] addBtn2.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn2 setBackgroundColor: [UIColor grayColor]; [addBtn2 addTarget: self action: @ selector (role) forControlEvents: role]; [self. view addSubview: addBtn2]; UIButton * addBtn3 = [[UIButton alloc] initWithFrame: CGRectMake (, 60, 30)]; [addBtn3 setTitle: @ "overlay" forState: Unknown]; addBtn3.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn3 setBackgroundColor: [UIColor grayColor]; [addBtn3 addTarget: self action: @ selector (addSecquece) forControlEvents: role. view addSubview: addBtn3]; UIButton * addBtn4 = [[UIButton alloc] initWithFrame: CGRectMake (, 60, 30)]; [addBtn4 setTitle: @ "Move Up" forState: UIControlStateNormal]; addBtn4.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn4 setBackgroundColor: [UIColor grayColor]; [addBtn4 addTarget: self action: @ selector (forUpMove) forControlEvents: role]; [self. view addSubview: addBtn4]; UIButton * addBtn5 = [[UIButton alloc] future: CGRectMake (290,70, 60, 30)]; [addBtn5 setTitle: @ "Move Down" forState: Unknown]; addBtn5.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn5 setBackgroundColor: [UIColor grayColor]; [addBtn5 addTarget: self action: @ selector (forDownMove) forControlEvents: role]; [self. view addSubview: addBtn5]; UIButton * addBtn6 = [[UIButton alloc] initWithFrame: CGRectMake (10,120,120, 30)]; [addBtn6 setTitle: @ "Change Up and down" forState: Unknown]; addBtn6.titleLabel. font = [UIFont systemFontOfSize: 13.0f]; [addBtn6 setBackgroundColor: [UIColor grayColor]; [addBtn6 addTarget: self action: @ selector (upForDown) forControlEvents: role]; [self. view addSubview: addBtn6];} # add layer-(void) addDract {viewA = [[UIView alloc] initWithFrame: CGRectMake (100,250,150,150)]; viewA. backgroundColor = [UIColor greenColor]; [self. view addSubview: viewA] ;}# pragma mark deletes a layer-(void) removeDract {[viewA removeFromSuperview];} # pragma mark layer superposition order first added in the following and then added in the above-(void) addSecquece {viewB = [[UIView alloc] initWithFrame: CGRectMake (110,260,150,150)]; viewB. backgroundColor = [UIColor redColor]; [self. view addSubview: viewB]; viewC = [[UIView alloc] initWithFrame: CGRectMake (120,270,150,150)]; viewC. backgroundColor = [UIColor yellowColor]; [self. view addSubview: viewC] ;}# pragma mark layer move up-(void) forUpMove {[self. view bringSubviewToFront: viewA] ;}# pragma mark layer move down-(void) forDownMove {[self. view sendSubviewToBack: viewA] ;}# pragma mark transpose-(void) upForDown {NSInteger indexC = [[self. view subviews] indexOfObject: viewC]; NSInteger indexA = [[self. view subviews] indexOfObject: viewA]; [self. view exchangeSubviewAtIndex: indexC withSubviewAtIndex: indexA];} @ end

 

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.