博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIView-图层方法
阅读量:7028 次
发布时间:2019-06-28

本文共 4014 字,大约阅读时间需要 13 分钟。

////  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

 

转载于:https://www.cnblogs.com/ak23173969/p/4479274.html

你可能感兴趣的文章
hdu 1028
查看>>
php Ajax Post GET传值
查看>>
什么样的终端才是最合适桌面虚拟化的呢?
查看>>
jQuery – 随机排列 item
查看>>
Oracle function
查看>>
FNDLOAD使用大全
查看>>
oracle本地服务名配置说明
查看>>
JS isNaN 方法使用说明
查看>>
android Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
查看>>
发现来博客园比去csdn早
查看>>
转 ofbiz权限判断语法整理
查看>>
从身边小事做起,让流程管理观念成为习惯
查看>>
Windows 8 安装之后怎样更改产品码
查看>>
ISO Latin-1字符集
查看>>
jQuery基本过滤选择器
查看>>
android ListView实现圆角实例教程二
查看>>
360桌面JSAPI一个诡异的bug:客户端与网页通过js通信
查看>>
struts2 spring3 整合
查看>>
ASP.NET Web开发框架之六 数据库文档方法,工具和实践
查看>>
HDU 4405 Aeroplane chess(概率DP求期望)
查看>>