UIView-圖層方法,uiview-圖層

來源:互聯網
上載者:User

UIView-圖層方法,uiview-圖層

////  ViewController.m//  UIView-圖層概念////  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:@"圖層概念"];        UIButton *addBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(10,70, 60, 30)];    [addBtn1 setTitle:@"增加" forState:UIControlStateNormal];    addBtn1.titleLabel.font=[UIFont systemFontOfSize:13.0f];    [addBtn1 setBackgroundColor:[UIColor grayColor]];    [addBtn1 addTarget:self action:@selector(addDract) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:addBtn1];        UIButton *addBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(80,70, 60, 30)];    [addBtn2 setTitle:@"刪除" forState:UIControlStateNormal];    addBtn2.titleLabel.font=[UIFont systemFontOfSize:13.0f];    [addBtn2 setBackgroundColor:[UIColor grayColor]];    [addBtn2 addTarget:self action:@selector(removeDract) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:addBtn2];        UIButton *addBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(150,70, 60, 30)];    [addBtn3 setTitle:@"疊加" forState:UIControlStateNormal];    addBtn3.titleLabel.font=[UIFont systemFontOfSize:13.0f];    [addBtn3 setBackgroundColor:[UIColor grayColor]];    [addBtn3 addTarget:self action:@selector(addSecquece) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:addBtn3];        UIButton *addBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(220,70, 60, 30)];    [addBtn4 setTitle:@"上移" forState:UIControlStateNormal];    addBtn4.titleLabel.font=[UIFont systemFontOfSize:13.0f];    [addBtn4 setBackgroundColor:[UIColor grayColor]];    [addBtn4 addTarget:self action:@selector(forUpMove) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:addBtn4];        UIButton *addBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(290,70, 60, 30)];    [addBtn5 setTitle:@"下移" forState:UIControlStateNormal];    addBtn5.titleLabel.font=[UIFont systemFontOfSize:13.0f];    [addBtn5 setBackgroundColor:[UIColor grayColor]];    [addBtn5 addTarget:self action:@selector(forDownMove) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:addBtn5];        UIButton *addBtn6 = [[UIButton alloc] initWithFrame:CGRectMake(10,120, 120, 30)];    [addBtn6 setTitle:@"上下調換" forState:UIControlStateNormal];    addBtn6.titleLabel.font=[UIFont systemFontOfSize:13.0f];    [addBtn6 setBackgroundColor:[UIColor grayColor]];    [addBtn6 addTarget:self action:@selector(upForDown) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:addBtn6];}#pragma mark 增加圖層-(void)addDract{    viewA= [[UIView alloc] initWithFrame:CGRectMake(100, 250, 150, 150)];    viewA.backgroundColor=[UIColor greenColor];     [self.view addSubview:viewA];}  #pragma mark 刪除圖層-(void)removeDract{    [viewA removeFromSuperview];}#pragma mark 圖層疊加順序 先添加的在下面 後添加的在上面-(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 圖層向上移-(void)forUpMove{    [self.view bringSubviewToFront:viewA];}#pragma mark 圖層向下移-(void)forDownMove{    [self.view sendSubviewToBack:viewA];    }#pragma mark 上下調換-(void)upForDown{    NSInteger indexC= [[self.view subviews] indexOfObject:viewC];    NSInteger indexA= [[self.view subviews] indexOfObject:viewA];    [self.view exchangeSubviewAtIndex:indexC withSubviewAtIndex:indexA];}@end

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.