读书人

UIView详解一

发布时间: 2013-09-06 10:17:17 作者: rapoo

UIView详解1

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

第一、UIView的可视化属性

1. backgroundColor 背景属性

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

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

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

6. clearsContextBeforeDrawingA 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:

property 返回该view的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 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]);





读书人网 >移动开发

热点推荐