一个UIView的实例就是一个视图,表示的是屏幕上的一块矩形区域,负责这块矩形区域的描绘以及和用户的交互。

第一、UIView的可视化属性

1. backgroundColor  背景属性

2. hidden  表示该view是否隐藏,

hidden属性为YES时视图隐藏,否则不隐藏。

3. alpha  为0时完全透明,为1时完全不透明

注意事项:

当视图完全透明或者隐藏时,不能响应触摸消息。

也就是alpha等于0.0或者hidden为YES的时候,但是当alpha<0.01的时候,视图就已经接收不到消息了。

视图的alpha值会影响子视图的绘制,但是子视图的alpha值不变。

4. opaque  property
这是一个优化属性,如果该值为YES, 那么绘图在绘制该视图的时候把整个视图当作不透明对待。这样,绘图系统在执行绘图过程中会优化一些操作并提升系统性能;如果是设置为NO, 绘图系统将其和其他内容平等对待,不去做优化操作。为了性能方面的考量,默认被置为YES(意味着‘优化’)。
另一方面,这个消息和alpha 是有关系的。 一个不透明视图需要整个边界里面的内容都是不透明的。基于这个原因,opaque设置为YES,要求对应的alpha必须为1.0。如果一个UIView实例opaque被设置为YES, 而同时它又没有完全填充它的边界(bounds),或者它包含了整个或部分的透明的内容视图,那么将会导致未知的结果。
因此,如果视图部分或全部支持透明,那么你必须把opaque这个值设置为NO. 

5. clipsToBounds

在类的层次结构中,如果clipsTobounds设为YES,超出superView的部分subview就不会显示,否则会做显示, 默认情况下是NO。

6. clearsContextBeforeDrawing

A Boolean value that determines whether the receiver’s bounds should be automatically cleared before drawing.

7. layerClass和 layer  property 跟Core Animation layer有关

第二、管理视图层次

1. superview  property 返回该view的superView

sample:

[self.windowaddSubview:self.viewController.view];

NSLog(@"the superView is %@",[self.viewController.viewsuperview]);

2. subviews  property 返回该view的subviews

sample:

NSLog(@"the suberViews are %@",[self.windowsubviews]);

3. window
  property 返回该view的window,如果没有返回nil

NSLog(@"the window is %@",[self.viewController.viewwindow]);

4. – addSubview:

5. – bringSubviewToFront:

把指定的子view放到最顶层,其父视图调用bringSubviewToFront()方法。

sample:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2];
[self.view bringSubviewToFront:button]; }

6.--sendSubviewToBack:

将一个UIView层推送到背后只需要调用其父视图的 sendSubviewToBack()方法。

sample:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2];
[self.view sendSubviewToBack:button2]; //[self.view bringSubviewToFront:button]; }

7.– removeFromSuperview

sample:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2]; [button removeFromSuperview];
}

8. – insertSubview:atIndex:

Parameters

view

The view to insert. This value cannot be nil.

index

The index in the array of the subviews property at which to insert the view. Subview indices start at0 and cannot be greater than the number of subviews.

sample:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2]; UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
button3.backgroundColor=[UIColor greenColor];
[self.view insertSubview:button3 atIndex:2];
}

9.– insertSubview:aboveSubview:

Inserts a view above another view in the view hierarchy.

- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview

sample:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2]; UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
button3.backgroundColor=[UIColor greenColor]; [self.view insertSubview:button3 aboveSubview:button];
}

10.– insertSubview:belowSubview:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2]; UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
button3.backgroundColor=[UIColor greenColor];
[self.view insertSubview:button3 belowSubview:button];
}

11.– exchangeSubviewAtIndex:withSubviewAtIndex:

- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2

Parameters

index1

The index of the first subview in the receiver.

index2

The index of the second subview in the receiver.

sample:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 50, 50)] autorelease];
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button]; UIButton *button2=[[[UIButton alloc] initWithFrame:CGRectMake(130, 130, 50, 50)] autorelease];
button2.backgroundColor=[UIColor blueColor]; [self.view addSubview:button2]; UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
button3.backgroundColor=[UIColor greenColor];
[self.view addSubview:button3];
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:3];
}

12
– isDescendantOfView:

Returns a Boolean value indicating whether the receiver is a subview of a given view or identical to that view.

- (BOOL)isDescendantOfView:(UIView *)view

sample:

NSLog(@"the result is %d",[button3isDescendantOfView:self.view]);

UIView详解1的更多相关文章

  1. UIView详解

    MVC架构模式   MVC(Model-View-Controller)是实现数据和显示数据的视图分离的架构模式(有一定规模的应用都应该实现数据和显示的分离).其中,M代表模型,就是程序中使用的数据和 ...

  2. UI第三节——UIView详解

    - (void)viewDidLoad { [super viewDidLoad]; UIView *redView = [[UIView alloc] initWithFrame:CGRectMak ...

  3. UIView详解2

    第三.Configuring the Event-Related Behavior 1.  userInteractionEnabled  property A Boolean value that ...

  4. 《iOS 7 应用开发实战详解》

    <iOS 7 应用开发实战详解> 基本信息 作者: 朱元波    管蕾 出版社:人民邮电出版社 ISBN:9787115343697 上架时间:2014-4-25 出版日期:2014 年5 ...

  5. 详解CALayer 和 UIView的区别和联系

    详解CALayer 和 UIView的区别和联系   前言 前面发了一篇iOS 面试的文章,在说到 UIView 和 CALayer 的区别和联系的时候,被喵神指出没有切中要点,所以这里就 CALay ...

  6. 【好程序员笔记分享】——UIView与CALayer详解

    -iOS培训,iOS学习-------型技术博客.期待与您交流!------------ UIView与CALayer详解 研究Core Animation已经有段时间了,关于Core Animati ...

  7. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  8. iOS开发——加载、滑动翻阅大量图片解决方案详解

    加载.滑动翻阅大量图片解决方案详解     今天分享一下私人相册中,读取加载.滑动翻阅大量图片解决方案,我想强调的是,编程思想无关乎平台限制. 我要详细说一下,在缩略图界面点击任意小缩略图后,进入高清 ...

  9. UI第六节——UINavigationController 详解

    1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIViewController,里面就是空的,什么也没有. ...

随机推荐

  1. webform中listbox运用,2个相互传值练习1:

    AppendDataBoundItems(将数据绑定项追加到静态声明列表项上)属性改为Ture;SelectionMode(列表的选择模式改为多项)属性改为Multiple using System; ...

  2. FFTW程序Demo

    #include<stdio.h> #include<stdlib.h> #include <fftw3.h> #include<string.h> # ...

  3. JavaSE学习总结第01天_Java概述

      01.01 计算机概述 计算机(Computer):全称电子计算机,俗称电脑. 是一种能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备. 由硬件和软件所组成,没有安装任何软件的计算机称 ...

  4. Python:爬取乌云厂商列表,使用BeautifulSoup解析

    在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...

  5. werkzeug中reloader的实现

    在用flask开发时,如果把use_reloader设为True(debug设为True也能实现),那当你修改了app代码或调用环境发生改变时,服务器会自动重启,如下 * Detected chang ...

  6. Python之路:Python 基础(二)

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'lenliu' print name 下面的结论对吗?(对) 外层变量,可以被 ...

  7. hdu 4180

    题意; 求接近规定 分数 的 最大分数用到 farey 数列的第二条性质 1 #include <iostream> #include<stdio.h> using names ...

  8. javascript 检测密码强度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Java学习之开篇—个人随想

    现在大三上学期了,家里希望考研,不然觉得我这学校不好找工作,我自己觉得工作还是靠自己,学校就像给人第一眼感觉那样,虽然重要但也只会吸引HR多看两眼,真正留得住HR的还是要有拿的出手的技能. 当初凭着对 ...

  10. Swift - 1 (常量、变量、字符串、数组、字典、元组、循环、枚举、函数)

    Swift 中导入类库使用import,不再使用<>,导入自定义不再使用"" import Foundation 1> 声明变量和常量 在Swift中使用 &qu ...