UI1_UIView层操作

//
//  ViewController.m
//  UI1_UIView层操作
//
//  Created by zhangxueming on 15/7/1.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      //self.view.backgroundColor=[UIColor cyanColor];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 320, 100)];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];

    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(20, 140, 320, 100)];
    greenView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:greenView];

    UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(30, 180, 320, 100)];
    yellowView.backgroundColor = [UIColor yellowColor];
    yellowView.alpha= 1.0;//值越大越不透明
    [self.view addSubview:yellowView];
    //先添加的视图在self.view的最底层, 后添加的视图在self.view的最顶层
    //父视图 子视图
    //获取父视图
    UIView *superView = [redView superview];
    superView.backgroundColor = [UIColor cyanColor];
    [yellowView superview].backgroundColor = [UIColor whiteColor];
    //获取子视图数组
    NSArray *subViews = [self.view subviews];
    ((UIView *)[subViews objectAtIndex:0]).backgroundColor = [UIColor orangeColor];
    NSLog(@"count = %li", subViews.count);

    //把子视图移到最顶层显示
    [self.view bringSubviewToFront:redView];
    //把子视图移动到最底层显示
    [self.view sendSubviewToBack:redView];

    UIView *insertView = [[UIView alloc] initWithFrame:CGRectMake(10, 160, 350, 100)];
    insertView.backgroundColor = [UIColor blueColor];
    //在指定下标位置增加视图
    //[self.view insertSubview:insertView atIndex:1];
    //在指定视图上层增加视图
    //[self.view insertSubview:insertView aboveSubview:greenView];
    //在指定视图下层增加视图
    [self.view insertSubview:insertView belowSubview:greenView];
    //交换两个位置的视图
    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:3];
      self.view.backgroundColor=[UIColor cyanColor];
    //[self.view removeFromSuperview];
    if([self.view superview])
    {
        NSLog(@"23");
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
时间: 2024-08-26 17:00:26

UI1_UIView层操作的相关文章

yii model层操作总结

yii model层操作属性和方法总结. tableName – 设置Model所对应的表名,例如: public function tableName(){return 'gshop_order_ext';} rules – 设置Model里各字段的验证规则 relations – 设置关联规则 attributeLabels – 设置各字段的别名 safeAttributes – 设置可以修改属性的字段 beforeValidate和afterValidate – 字段验证前和验证后执行的函

Hibernate深入浅出(九)持久层操作——数据保存&批量操作

数据保存: 1)session.save session.save方法用于实体对象到数据库的持久化操作.也就是说,session.save方法调用与实体对象所匹配的Insert SQL,将数据插入库表. 结合一个简单实例来进行讨论: 1 2 3 4 5 TUser user = new TUser(); user.setName("Luna"); Transaction tx = session.beginTransaction(); session.save(user); tx.co

安卓java层操作数据库

一.在Android中查询数据库用到两个重要的类:  1.SQLiteDatabase:用来创建,删除,执行SQL命令,并执行其他常见的数据库管理任务. 2.query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) 返回Cursor对象 table:数据库里边表的名称 columns:需要查询出来数据库

linux下GPIO的用户层操作(sysfs)

linux的GPIO通过sysfs为用户提供服务,下面是linux kernel里的说明文档,学习一下. GPIO Sysfs Interface for Userspace ================================== Platforms which use the "gpiolib" implementors framework may choose to configure a sysfs user interface to GPIOs. This is

JAVA实现DAO基本层CRUD操作

随着shh2各种操作方便框架.越来越多JAVA WEB效率,可是,假设在不了解这些框架使用的场合的情况下,一拿到项目就盲目地选择这些框架进行系统架构的搭建,就有可能造成非常多不是必需的资源浪费. 在项目开发中.对数据库的CRUD操作我们一般都是无法避免的操作,尽管hibernate封装的非常完美,可是.因为本人对这个框架的底层原理不是非常了解,每次使用的时候心里总认为没底.代码一旦出现异常,非常多时候都没法高速有效地解决.因此,为了让代码异常处理风险控制在自己的可控范围内,还是决定先将数据的CR

JAVA实现DAO层基本CRUD操作

随着shh2框架各种操作的便利性,越来越多的JAVA WEB开发人员选择通过加入这些框架以提高开发效率,但是,如果在不了解这些框架使用的场合的情况下,一拿到项目就盲目地选择这些框架进行系统架构的搭建,就有可能造成很多没必要的资源浪费. 在项目开发中,对数据库的CRUD操作我们一般都是无法避免的操作,虽然hibernate封装的很完美,但是,由于本人对这个框架的底层原理不是很了解,每次使用的时候心里总觉得没底,代码一旦出现异常,很多时候都没法快速有效地解决,因此,为了让代码异常处理风险控制在自己的

一步一步ITextSharp 低级操作函数使用

首先说一下PDF文档的结构: 分为四层,第一层和第四层由低级操作来进行操作,第二层.第三层由高级对象操作 第一层操作只能使用PdfWriter.DirectContent操作,第四层使用DirectContentUnder操作. 第二层和第三层的PdfContentByte是由IText内部操作,没有提供api接口. 图形和文本状态解释 图形状态,就是作图时对图形一些环境设置, 使用低级操作输出文本或图形前,应该设置操作环境,并且操作完成后,应该恢复操作前的环境. 使用低级操作是非常复杂的一般情

Socket层实现系列 — connect()的实现

主要内容:connect()的Socket层实现.期间进程的睡眠和唤醒. 内核版本:3.15.2 我的博客:http://blog.csdn.net/zhangskd 应用层 int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); Connects the socket referred to by the file descriptor sockfd to the address specifi

Bluetooth Low Energy链路层

1. 介绍 1.1 链路状态机 链路层操作可以描述为链路状态机(The Link Layer State Machine) 链路状态机有如下五种状态 - Standby State: 准备,不传输或接受数据包 - Advertising State: 广播, advertiser,发送advertising channel packets,接受来自scanner的响应 - Scanning State: 监听/扫描, scanner,监听来自advertiser的advertising chan